Coverity fixing

This commit is contained in:
dmh 2014-08-17 12:03:23 -06:00
parent 2838b5ac2e
commit 18eb1c1126
11 changed files with 43 additions and 34 deletions

View File

@ -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,

View File

@ -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"

View File

@ -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);
}

View File

@ -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;i<rank;i++) {
@ -1546,6 +1547,7 @@ showprojection(NCDAPCOMMON* dapcomm, CDFnode* var)
"_projection",
ncbyteslength(projection),
ncbytescontents(projection));
ncbytesfree(projection);
return ncstat;
}
@ -1585,7 +1587,7 @@ fprintf(stderr,"seqcountconstraints: %s\n",ncbytescontents(seqcountconstraints))
/* WARNING: we are now switching to datadds tree */
xseq = seq->attachment;
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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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];

View File

@ -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;

View File

@ -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;

View File

@ -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"

View File

@ -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);
}