From 18eb1c11260fb5d78712978f4abfa17e54129b13 Mon Sep 17 00:00:00 2001 From: dmh Date: Sun, 17 Aug 2014 12:03:23 -0600 Subject: [PATCH] Coverity fixing --- include/nctime.h | 4 +++- libdap2/env | 10 +++++----- libdap2/getvara.c | 11 ++++++----- libdap2/ncd2dispatch.c | 20 +++++++++++++------- libdap2/ncdaperr.c | 2 +- libdispatch/ddispatch.c | 3 +-- libdispatch/dv2i.c | 2 +- libdispatch/nctime.c | 2 ++ libdispatch/ncuri.c | 13 +++++++------ ncgen/env | 4 ++-- ncgen/genchar.c | 6 ++---- 11 files changed, 43 insertions(+), 34 deletions(-) diff --git a/include/nctime.h b/include/nctime.h index 19f6356aa..7f0d29156 100644 --- a/include/nctime.h +++ b/include/nctime.h @@ -33,6 +33,8 @@ typedef struct bounds_node bounds_node_t; #define CD_NULL_MONTH 1 /* Null month value */ #define CD_NULL_YEAR 0 /* Null year value, component time */ +/* Why do we have same enum defined twice? */ + typedef enum CdTimeUnit { CdBadTimeUnit = 0, CdMinute = 1, @@ -46,7 +48,7 @@ typedef enum CdTimeUnit { } CdTimeUnit; typedef enum cdUnitTime { - cdBadUnit = CdBadTimeUnit, + cdBadUnit = CdBadTimeUnit, cdMinute = CdMinute, cdHour = CdHour, cdDay = CdDay, diff --git a/libdap2/env b/libdap2/env index f82fcbdd2..7a554f7b5 100644 --- a/libdap2/env +++ b/libdap2/env @@ -1,14 +1,14 @@ +#TOP="/home/dmh/mach/netcdf-c" +TOP="/cygdrive/f/git/netcdf-c" + + alias xx="cd ..;make; cd libdap2" PARMS=""; ARGS=""; CON="" ; CE=""; OCON="" ; VAR=""; SHARP='#' alias q0=;alias qq=;alias qv=;alias q=;alias qh=;alias qqh=;alias qall=;alias qv=;alias qo=; -TOP="/home/dmh/mach/netcdf-c" -#TOP="/cygdrive/f/git/netcdf-c" -F='http://carbon.dkrz.de/thredds/dodsC/cordex/output/EUR-11/KNMI/ICHEC-EC-EARTH/historical/r1i1p1/KNMI-RACMO22E/v1/day/tas/v20140313/tas_EUR-11_ICHEC-EC-EARTH_historical_r1i1p1_KNMI-RACMO22E_v1_day_19500101-19501231.nc' - -VAR=rlon +F="http://thredds.aodn.org.au/thredds/fileServer/IMOS/ANMN/NSW/PH100/Velocity/IMOS_ANMN-NSW_AETVZ_20131127T230000Z_PH100_FV01_PH100-1311-Workhorse-ADCP-109.5_END-20140306T010000Z_C-20140521T053527Z.nc" #PROG=./ncd PROG="$TOP/ncdump/ncdump" diff --git a/libdap2/getvara.c b/libdap2/getvara.c index 5d3f3577d..0a70fbcf2 100644 --- a/libdap2/getvara.c +++ b/libdap2/getvara.c @@ -415,11 +415,11 @@ save = (DCEnode*)varaprojection; ncstat = moveto(dapcomm,varainfo,varainfo->cache->datadds,data); if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto fail;} - nclistfree(vars); - dcefree((DCEnode*)varaprojection); - dcefree((DCEnode*)fetchconstraint); - freegetvara(varainfo); fail: + if(vars != null) nclistfree(vars); + if(varaprojection != null) dcefree((DCEnode*)varaprojection); + if(fetchconstraint != null) dcefree((DCEnode*)fetchconstraint); + if(varainfo != null) freegetvara(varainfo); if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); return THROW(ncstat); } @@ -958,6 +958,7 @@ extractstring( dapodom_next(odom); } dapodom_free(odom); + odom = NULL; } /* Get each string in turn, slice it by applying the string dimm and store in user supplied memory @@ -967,8 +968,8 @@ extractstring( slicestring(conn,s,&segment->slices[rank0],memory); free(s); } - nclistfree(strings); done: + if(strings != null) nclistfree(strings); if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); return THROW(ncstat); } diff --git a/libdap2/ncd2dispatch.c b/libdap2/ncd2dispatch.c index 26ea02d1a..f1f80ab05 100644 --- a/libdap2/ncd2dispatch.c +++ b/libdap2/ncd2dispatch.c @@ -45,7 +45,7 @@ static NCerror makeseqdim(NCDAPCOMMON*, CDFnode* seq, size_t count, CDFnode** sq static NCerror countsequence(NCDAPCOMMON*, CDFnode* xseq, size_t* sizep); static NCerror freeNCDAPCOMMON(NCDAPCOMMON*); static NCerror fetchtemplatemetadata(NCDAPCOMMON*); -static int fieldindex(CDFnode* parent, CDFnode* child); +static size_t fieldindex(CDFnode* parent, CDFnode* child); static NCerror computeseqcountconstraints(NCDAPCOMMON*, CDFnode*, NCbytes*); static void computeseqcountconstraintsr(NCDAPCOMMON*, CDFnode*, CDFnode**); static void estimatevarsizes(NCDAPCOMMON*); @@ -581,7 +581,7 @@ fprintf(stderr,"ncdap3: final constraint: %s\n",dapcomm->oc.url->constraint); done: if(drno != NULL) NCD2_close(drno->ext_ncid); - if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); + ncstat = ocerrtoncerr(ocstat); return THROW(ncstat); } @@ -1531,6 +1531,7 @@ showprojection(NCDAPCOMMON* dapcomm, CDFnode* var) if(i > 0) ncbytescat(projection,"."); ncbytescat(projection,node->ocname); } + nclistfree(path); /* Now, add the dimension info */ rank = nclistlength(var->array.dimset0); for(i=0;iattachment; ncstat = countsequence(dapcomm,xseq,&seqsize); - if(ncstat) goto fail; + if(ncstat != NC_NOERR) goto fail; #ifdef DEBUG fprintf(stderr,"sequencesize: %s = %lu\n",seq->ocname,(unsigned long)seqsize); @@ -1594,6 +1596,8 @@ fprintf(stderr,"sequencesize: %s = %lu\n",seq->ocname,(unsigned long)seqsize); /* throw away the fetch'd trees */ unattach(dapcomm->cdf.ddsroot); freecdfroot(dxdroot); +#if 0 +Note sure what this is doing? if(ncstat != NC_NOERR) { /* Cannot get DATADDDS*/ char* code; @@ -1606,12 +1610,14 @@ fprintf(stderr,"sequencesize: %s = %lu\n",seq->ocname,(unsigned long)seqsize); } ocstat = OC_NOERR; } +#endif + if(sizep) *sizep = seqsize; fail: ncbytesfree(seqcountconstraints); oc_data_free(conn,rootcontent); - if(ocstat) ncstat = ocerrtoncerr(ocstat); + ncstat = ocerrtoncerr(ocstat); return ncstat; } @@ -1709,7 +1715,7 @@ countsequence(NCDAPCOMMON* dapcomm, CDFnode* xseq, size_t* sizep) done: nclistfree(path); - if(ocstat) ncstat = ocerrtoncerr(ocstat); + ncstat = ocerrtoncerr(ocstat); return THROW(ncstat); } @@ -2001,7 +2007,7 @@ fprintf(stderr,"full template:\n%s",dumptree(dapcomm->cdf.fullddsroot)); done: nullfree(ce); - if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); + ncstat = ocerrtoncerr(ocstat); return ncstat; } @@ -2055,7 +2061,7 @@ fprintf(stderr,"constrained:\n%s",dumptree(dapcomm->cdf.ddsroot)); fail: nullfree(ce); - if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); + ncstat = ocerrtoncerr(ocstat); return ncstat; } diff --git a/libdap2/ncdaperr.c b/libdap2/ncdaperr.c index adae25791..476cd553d 100644 --- a/libdap2/ncdaperr.c +++ b/libdap2/ncdaperr.c @@ -8,7 +8,7 @@ NCerror ocerrtoncerr(OCerror ocerr) { - if(ocerr >= 0) return ocerr; /* really a system error*/ + if(ocerr > 0) return ocerr; /* really a system error*/ switch (ocerr) { case OC_NOERR: return NC_NOERR; case OC_EBADID: return NC_EBADID; diff --git a/libdispatch/ddispatch.c b/libdispatch/ddispatch.c index 898919085..72f902cf1 100644 --- a/libdispatch/ddispatch.c +++ b/libdispatch/ddispatch.c @@ -143,12 +143,11 @@ NC_urlmodel(const char* path) } if(model == 0) { - /* Now look at the protocol */ for(protolist=ncprotolist;protolist->protocol;protolist++) { if(strcmp(tmpurl->protocol,protolist->protocol) == 0) { model |= protolist->modelflags; if(protolist->substitute) { - if(tmpurl->protocol) free(tmpurl->protocol); + free(tmpurl->protocol); tmpurl->protocol = strdup(protolist->substitute); } break; diff --git a/libdispatch/dv2i.c b/libdispatch/dv2i.c index 10c8bd227..48e83d992 100644 --- a/libdispatch/dv2i.c +++ b/libdispatch/dv2i.c @@ -247,7 +247,6 @@ nc_inq_rec( if(status != NC_NOERR) return status; - *nrecvarsp = 0; if (recdimid == -1) return NC_NOERR; @@ -257,6 +256,7 @@ nc_inq_rec( if (nrecvarsp != NULL) *nrecvarsp = (size_t)nrvars; + if (recvarids != NULL) for (varid = 0; varid < nrvars; varid++) recvarids[varid] = rvarids[varid]; diff --git a/libdispatch/nctime.c b/libdispatch/nctime.c index 539a673c6..33e6a7d00 100644 --- a/libdispatch/nctime.c +++ b/libdispatch/nctime.c @@ -827,6 +827,7 @@ cdComp2Rel(cdCalenType timetype, cdCompTime comptime, char* relunits, double* re Cdh2e(&humantime,&etm); /* Calculate relative time value for months or hours */ deltime.count = 1; + /* Coverity[MIXED_ENUMS] */ deltime.units = (CdTimeUnit)unit; switch(unit){ case cdWeek: case cdDay: case cdHour: case cdMinute: case cdSecond: @@ -1040,6 +1041,7 @@ cdRel2Comp(cdCalenType timetype, char* relunits, double reltime, cdCompTime* com } deltime.count = 1; + /* Coverity[MIXED_ENUMS] */ deltime.units = (CdTimeUnit)baseunits; humantime.year = base_comptime.year; diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c index 3e401600a..b1795ed04 100644 --- a/libdispatch/ncuri.c +++ b/libdispatch/ncuri.c @@ -21,7 +21,7 @@ static int failpoint = 0; #define THROW(n) {failpoint=(n); goto fail;} #else -#define THROW(n) +#define THROW(n) {goto fail;} #endif @@ -185,7 +185,7 @@ ncuriparse(const char* uri0, NCURI** durip) } } if(proto == NULL) - {THROW(6); goto fail; /* illegal protocol*/} + {THROW(6); /* illegal protocol*/} /* skip // */ if(p[0] != '/' && p[1] != '/') @@ -252,7 +252,7 @@ ncuriparse(const char* uri0, NCURI** durip) /* check for empty host section */ if(*host == EOFCHAR) - {THROW(13); goto fail;} + {THROW(13);} } @@ -315,7 +315,7 @@ ncuriparse(const char* uri0, NCURI** durip) /* do last minute empty check */ - if(protocol != NULL && *protocol == EOFCHAR) protocol = NULL; + if(*protocol == EOFCHAR) protocol = NULL; if(user != NULL && *user == EOFCHAR) user = NULL; if(pwd != NULL && *pwd == EOFCHAR) pwd = NULL; if(host != NULL && *host == EOFCHAR) host = NULL; @@ -462,9 +462,9 @@ ncuribuild(NCURI* duri, const char* prefix, const char* suffix, int flags) int withconstraints = ((flags&NCURICONSTRAINTS)!=0 && duri->constraint != NULL); #ifdef NEWESCAPE - int encode = (flags&NCURIENCODE); + const int encode = (flags&NCURIENCODE); #else - int encode = 0; + const int encode = 0; #endif if(prefix != NULL) len += NILLEN(prefix); @@ -657,6 +657,7 @@ ncurilookup(NCURI* uri, const char* key, const char** resultp) i = ncuridecodeparams(uri); if(!i) return 0; } + /* Coverity[FORWARD_NULL] */ i = ncfind(uri->paramlist,key); if(i < 0) return 0; diff --git a/ncgen/env b/ncgen/env index 6fa2be716..039947698 100644 --- a/ncgen/env +++ b/ncgen/env @@ -1,7 +1,7 @@ # test: ../ncdump/cdl4/ref_const_test.cdl # test: ../ncdump/cdl4/ref_tst_chardata.cdl -K="-k3" -F="mrd.cdl" +K="-k1" +F="z.cdl" #B="-B12" DBG="-d" #DBG="-D2" diff --git a/ncgen/genchar.c b/ncgen/genchar.c index 73ab61814..b187fb44c 100644 --- a/ncgen/genchar.c +++ b/ncgen/genchar.c @@ -17,10 +17,10 @@ static void gen_chararrayr(Dimset*,int,int,Bytebuffer*,Datalist*,int,int,int); /* Matching strings to char variables, attributes, and vlen constants is challenging because it is desirable to mimic -the original ncgen. The "algorithms" used there have no +the original ncgen(3). The "algorithms" used there have no simple characterization (such as "abc" == {'a','b','c'}). So, this rather ugly code is kept in this file -and a variety of heuristics are used to mimic ncgen. +and a variety of heuristics are used to mimic ncgen3. The core algorithm is as follows. 1. Assume we have a set of dimensions D1..Dn, @@ -78,8 +78,6 @@ gen_chararray(Dimset* dimset, Datalist* data, Bytebuffer* databuf, Datalist* fil expectedsize = (xproduct * unitsize); - - gen_chararrayr(dimset,0,lastunlim,databuf,data,fillchar,unitsize,expectedsize); }