Skip to content

Commit

Permalink
Merge pull request #111 from wcohen/coverity202311
Browse files Browse the repository at this point in the history
Fixes for coverity reported issues in various files
  • Loading branch information
gcongiu authored Nov 8, 2023
2 parents ea3cc00 + 9a61dfe commit 70aeec3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/components/coretemp/linux-coretemp.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ generateEventList(char *base_dir)
retlen = snprintf(name, PAPI_MAX_STR_LEN, "%s:in%i_input", hwmonx->d_name, i);
if (retlen <= 0 || PAPI_MAX_STR_LEN <= retlen) {
SUBDBG("Unable to generate name %s:in%i_input\n", hwmonx->d_name, i);
closedir(d);
closedir(dir);
closedir(d);
return ( PAPI_EINVAL );
}

Expand Down Expand Up @@ -454,18 +455,18 @@ _coretemp_init_component( int cidx )
}

do {
char *strCpy;
strCpy=strncpy(_coretemp_native_events[i].name,t->name,PAPI_MAX_STR_LEN);
if (strCpy == NULL) HANDLE_STRING_ERROR;
int retlen;
retlen = snprintf(_coretemp_native_events[i].name, PAPI_MAX_STR_LEN, "%s", t->name);
if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;

strCpy=strncpy(_coretemp_native_events[i].path,t->path,PATH_MAX);
if (strCpy == NULL) HANDLE_STRING_ERROR;
retlen = snprintf(_coretemp_native_events[i].path, PATH_MAX, "%s", t->path);
if (retlen <= 0 || retlen >= PATH_MAX) HANDLE_STRING_ERROR;

strCpy=strncpy(_coretemp_native_events[i].units,t->units,PAPI_MIN_STR_LEN);
if (strCpy == NULL) HANDLE_STRING_ERROR;
retlen = snprintf(_coretemp_native_events[i].units, PAPI_MIN_STR_LEN, "%s", t->units);
if (retlen <= 0 || retlen >= PAPI_MIN_STR_LEN) HANDLE_STRING_ERROR;

strCpy=strncpy(_coretemp_native_events[i].description,t->description,PAPI_MAX_STR_LEN);
if (strCpy == NULL) HANDLE_STRING_ERROR;
retlen = snprintf(_coretemp_native_events[i].description, PAPI_MAX_STR_LEN, "%s",t->description);
if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;

_coretemp_native_events[i].stone = 0;
_coretemp_native_events[i].resources.selector = i + 1;
Expand Down
12 changes: 10 additions & 2 deletions src/components/net/linux-net.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ papi_vector_t _net_vector;
#define NET_INVALID_RESULT -1


// The following macro follows if a string function has an error. It should
// never happen; but it is necessary to prevent compiler warnings. We print
// something just in case there is programmer error in invoking the function.
#define HANDLE_STRING_ERROR {fprintf(stderr,"%s:%i unexpected string function error.\n",__FILE__,__LINE__); exit(-1);}

static NET_native_event_entry_t * _net_native_events=NULL;

static int num_events = 0;
Expand Down Expand Up @@ -343,8 +348,11 @@ _net_init_component( int cidx )
_net_native_events = (NET_native_event_entry_t*)
papi_malloc(sizeof(NET_native_event_entry_t) * num_events);
do {
strncpy(_net_native_events[i].name, t->name, PAPI_MAX_STR_LEN);
strncpy(_net_native_events[i].description, t->description, PAPI_MAX_STR_LEN);
int retlen;
retlen = snprintf(_net_native_events[i].name, PAPI_MAX_STR_LEN, "%s", t->name);
if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;
retlen = snprintf(_net_native_events[i].description, PAPI_MAX_STR_LEN, "%s", t->description);
if (retlen <= 0 || retlen >= PAPI_MAX_STR_LEN) HANDLE_STRING_ERROR;
_net_native_events[i].resources.selector = i + 1;
last = t;
t = t->next;
Expand Down
1 change: 1 addition & 0 deletions src/components/sysdetect/linux_cpu_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,5 +965,6 @@ get_vendor_id( void )
decode_vendor_string(vendor_string, &vendor_id);
}

fclose(fp);
return vendor_id;
}
2 changes: 2 additions & 0 deletions src/ctests/thrspecific.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Thread( void *arg )
printf( "Entry %d, Thread %#lx, Data Pointer %p, Value %d\n",
i, data.id[i], data.data[i], *( int * ) data.data[i] );
}
free(data.id);
free(data.data);
processing = 0;
}
}
Expand Down

0 comments on commit 70aeec3

Please sign in to comment.