diff --git a/src/components/coretemp/linux-coretemp.c b/src/components/coretemp/linux-coretemp.c index 634c8c374..43c2bfec7 100644 --- a/src/components/coretemp/linux-coretemp.c +++ b/src/components/coretemp/linux-coretemp.c @@ -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 ); } @@ -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; diff --git a/src/components/net/linux-net.c b/src/components/net/linux-net.c index c9c2c4d6d..93b052ec8 100644 --- a/src/components/net/linux-net.c +++ b/src/components/net/linux-net.c @@ -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; @@ -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; diff --git a/src/components/sysdetect/linux_cpu_utils.c b/src/components/sysdetect/linux_cpu_utils.c index ae8fa533f..dd08ec5e7 100644 --- a/src/components/sysdetect/linux_cpu_utils.c +++ b/src/components/sysdetect/linux_cpu_utils.c @@ -965,5 +965,6 @@ get_vendor_id( void ) decode_vendor_string(vendor_string, &vendor_id); } + fclose(fp); return vendor_id; } diff --git a/src/ctests/thrspecific.c b/src/ctests/thrspecific.c index e454b114a..864fdd1a3 100644 --- a/src/ctests/thrspecific.c +++ b/src/ctests/thrspecific.c @@ -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; } }