Merge pull request #1100 from Unidata/coverity0803.dmh

Clear up coverity complaints
This commit is contained in:
Ward Fisher 2018-08-06 11:30:45 -06:00 committed by GitHub
commit f473c53c06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 42 additions and 28 deletions

2
cf
View File

@ -1,6 +1,6 @@
#!/bin/bash
#NB=1
#DB=1
DB=1
#X=-x
#FAST=1

View File

@ -567,7 +567,8 @@ getlimitnumber(const char* limit)
case 'K': case 'k': multiplier = KILOBYTE; break;
default: break;
}
sscanf(limit,"%lu",&lu);
if(sscanf(limit,"%lu",&lu) != 1)
return 0;
return (lu*multiplier);
}

View File

@ -128,14 +128,17 @@ range(DCEparsestate* state, Object sfirst, Object sstride, Object slast)
/* Note: that incoming arguments are strings; we must convert to size_t;
but we do know they are legal integers or NULL */
sscanf((char*)sfirst,"%lu",&first); /* always defined */
if(slast != NULL)
sscanf((char*)slast,"%lu",&last);
else
if(sscanf((char*)sfirst,"%lu",&first) != 1) /* always defined */
return NULL;
if(slast != NULL) {
if(sscanf((char*)slast,"%lu",&last) != 1)
return NULL;
} else
last = first;
if(sstride != NULL)
sscanf((char*)sstride,"%lu",&stride);
else
if(sstride != NULL) {
if(sscanf((char*)sstride,"%lu",&stride) != 1)
return NULL;
} else
stride = 1; /* default */
if(stride == 0)
@ -158,7 +161,8 @@ Object
range1(DCEparsestate* state, Object rangenumber)
{
int range = -1;
sscanf((char*)rangenumber,"%u",&range);
if(sscanf((char*)rangenumber,"%u",&range) != 1)
range = -1;
if(range < 0) {
dceerror(state,"Illegal range index");
}
@ -199,7 +203,8 @@ array_indices(DCEparsestate* state, Object list0, Object indexno)
long long start = -1;
NClist* list = (NClist*)list0;
if(list == NULL) list = nclistnew();
sscanf((char*)indexno,"%lld",&start);
if(sscanf((char*)indexno,"%lld",&start) != 1)
start = -1;
if(start < 0) {
dceerror(state,"Illegal array index");
start = 1;

View File

@ -2090,7 +2090,7 @@ printhashmap(NC_hashmap* hm)
NC_hentry e = hm->table[i];
if(e.flags == ACTIVE) {
fprintf(stderr,"[%ld] flags=ACTIVE hashkey=%lu data=%p keysize=%u key=(%llu)|%s|\n",
(unsigned long)i,(unsigned long)e.hashkey,(void*)e.data,(unsigned)e.keysize,(unsigned long long)e.key,e.key);
(unsigned long)i,(unsigned long)e.hashkey,(void*)e.data,(unsigned)e.keysize,(unsigned long long)(uintptr_t)e.key,e.key);
running = 0;
} else if(e.flags == DELETED) {
fprintf(stderr,"[%ld] flags=DELETED hashkey=%lu\n",

View File

@ -200,7 +200,7 @@ nc4_close_netcdf4_file(NC_FILE_INFO_T *h5, int abort, int extractmem)
exit:
/* Free the nc4_info struct; above code should have reclaimed
everything else */
if(!retval && h5 != NULL)
if(!retval)
free(h5);
return retval;
}

View File

@ -1235,7 +1235,7 @@ nc4_read_grp_atts(NC_GRP_INFO_T *grp)
}
}
/* Unconditionally close the open attribute */
H5Aclose(attid);
(void)H5Aclose(attid);
attid = -1;
}

View File

@ -101,7 +101,7 @@ echo "*** Testing dynamic filters using nccopy"
rm -f ./unfiltered.nc ./filtered.nc ./tmp.nc ./filtered.dump ./tst_filter.txt
${NCGEN} -4 -lb -o unfiltered.nc ${srcdir}/unfiltered.cdl
echo " *** Testing simple filter application"
${NCCOPY} -F "/g/var,307,9,4" unfiltered.nc filtered.nc
${NCCOPY} -M0 -F "/g/var,307,9,4" unfiltered.nc filtered.nc
${NCDUMP} -s filtered.nc > ./tst_filter.txt
# Remove irrelevant -s output
sclean ./tst_filter.txt ./filtered.dump
@ -119,7 +119,7 @@ echo " *** Pass: pass-thru of filters"
echo " *** Testing -F none"
rm -f ./tst_filter.txt ./tst_filter2.txt ./tst_filter.nc
${NCCOPY} -F none ./filtered.nc ./tst_filter.nc
${NCCOPY} -M0 -F none ./filtered.nc ./tst_filter.nc
${NCDUMP} -s tst_filter.nc > ./tst_filter.txt
sed -e '/_Filter/p' -e d < ./tst_filter.txt >./tst_filter2.txt
test ! -s tst_filter2.txt
@ -127,7 +127,7 @@ echo " *** Pass: -F none"
echo " *** Testing -F var,none "
rm -f ./tst_filter.txt ./tst_filter.nc
${NCCOPY} -F "/g/var,none" ./filtered.nc ./tst_filter.nc
${NCCOPY} -M0 -F "/g/var,none" ./filtered.nc ./tst_filter.nc
${NCDUMP} -s tst_filter.nc > ./tst_filter.txt
sed -e '/_Filter/p' -e d < ./tst_filter.txt >tst_filter2.txt
test ! -s tst_filter2.txt

View File

@ -2133,6 +2133,8 @@ main(int argc, char**argv)
if(level >= 0)
nc_set_log_level(level);
}
#else
error("-L specified, but logging support not enabled");
#endif
break;
case 'F': /* optional filter spec for a specified variable */
@ -2154,9 +2156,13 @@ main(int argc, char**argv)
#else
error("-F requires netcdf-4");
#endif
break;
case 'M': /* set min chunk size */
#ifdef USE_NETCDF4
option_min_chunk_bytes = atol(optarg);
if(optarg == NULL)
option_min_chunk_bytes = -1;
else
option_min_chunk_bytes = atol(optarg);
if(option_min_chunk_bytes < 0)
error("-M value must be non-negative integer");
break;

View File

@ -217,7 +217,7 @@ main(int argc, char **argv)
break;
case 'D': {
int c0;
if(strlen(optarg) == 0) usage("missing -D argument");
if(optarg == NULL || strlen(optarg) == 0) usage("missing -D argument");
c0 = optarg[0];
if(c0 >= '0' && c0 <= '9') {/* debug level */
ocopt.debug.debuglevel = atoi(optarg); break;
@ -245,6 +245,8 @@ main(int argc, char **argv)
case 'o':
if(ocopt.output != NULL) fclose(ocopt.output);
if(optarg == NULL)
usage("-o does not specify a file name");
ocopt.output = fopen(optarg,"w");
if(ocopt.output == NULL)
usage("-o file not writeable");
@ -255,6 +257,8 @@ main(int argc, char **argv)
break;
case 'p':
if(optarg == NULL)
usage("-p does not specify an argument");
if(strcasecmp(optarg,"das")==0) ocopt.optdas=1;
else if(strcasecmp(optarg,"dds")==0) ocopt.optdds=1;
else if(strcasecmp(optarg,"data")==0) ocopt.optdatadds=1;
@ -280,7 +284,8 @@ main(int argc, char **argv)
if(ocopt.logging) {
ncloginit();
ncsetlogging(1);
nclogopen(NULL);
if(!nclogopen(NULL))
fprintf(stderr,"Failed to open logging output\n");
}
argc -= optind;
@ -479,10 +484,7 @@ processdata(OCflags flags)
if(ocopt.optdatadds) {
ocstat = oc_fetch(link,ocopt.url->query,OCDATADDS,flags,&dataddsroot);
if(ocstat) {
if(ocopt.url->query)
fprintf(stderr,"Cannot read DATADDS: %s\n",ocopt.surl);
else
fprintf(stderr,"Cannot read DATADDS: %s\n",ocopt.surl);
fprintf(stderr,"Cannot read DATADDS: %s\n",ocopt.surl);
exit(1);
}
if(ocopt.debug.dumpdds)
@ -556,8 +558,8 @@ printdata_container(OClink link, OCdatanode datanode, NCbytes* buffer, int istop
pushstack(field);
FAIL(printdata_indices(link,field,buffer,istoplevel));
popstack();
oc_data_free(link,field);
if(stat != OC_NOERR) break;
if(oc_data_free(link,field) != OC_NOERR)
break;
}
return stat;
}
@ -997,7 +999,7 @@ dumpdatanode(OClink link, OCdatanode datanode, size_t count, void* memory, NCbyt
OCtype atomtype;
OCtype octype;
NCbytes* path = NULL;
char* name;
char* name = NULL;
char id[1024];
char tmp[1024];
struct DUMPPATH* entry = NULL;

View File

@ -103,7 +103,7 @@ dap_unrecognizedresponse(DAPparsestate* state)
unsigned int httperr = 0;
int i;
char iv[32];
sscanf(state->lexstate->input,"%u ",&httperr);
(void)sscanf(state->lexstate->input,"%u ",&httperr);
sprintf(iv,"%u",httperr);
state->lexstate->next = state->lexstate->input;
/* Limit the amount of input to prevent runaway */