fix e-support YOP-841363 plus a number of coverity found bugs

This commit is contained in:
Dennis Heimbigner 2012-08-02 18:43:21 +00:00
parent 7163dc49d8
commit bc3a732e25
23 changed files with 173 additions and 92 deletions

View File

@ -386,6 +386,9 @@ NC_sync(NC *ncp);
extern int
NC_calcsize(const NC *ncp, off_t *filesizep);
extern int
NC_set_readonly(NC *ncp, int onezero);
/* End defined in nc.c */
/* Begin defined in v1hpg.c */

View File

@ -17,7 +17,7 @@
extern void ncloginit(void);
extern void ncsetlogging(int tf);
extern void nclogopen(const char* file);
extern int nclogopen(const char* file);
extern void nclogclose(void);
/* The tag value is an arbitrary integer */

View File

@ -864,10 +864,15 @@ NCerror
computeprojectedvars(NCDAPCOMMON* dapcomm, DCEconstraint* constraint)
{
NCerror ncstat = NC_NOERR;
NClist* vars = nclistnew();
NClist* vars = NULL;
int i;
vars = nclistnew();
if(dapcomm->cdf.projectedvars != NULL)
nclistfree(dapcomm->cdf.projectedvars);
dapcomm->cdf.projectedvars = vars;
if(constraint == NULL || constraint->projections == NULL)
goto done;

View File

@ -24,6 +24,7 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
OCerror ocstat = OC_NOERR;
NClist* allnodes;
OClink conn;
char* ocname = NULL;
conn = nccomm->oc.conn;
@ -37,7 +38,6 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
for(i=0;i<nclistlength(allnodes);i++) {
CDFnode* node = (CDFnode*)nclistget(allnodes,i);
OCddsnode ocnode = node->ocnode;
char* ocname;
size_t attrcount;
OCtype ocetype;
@ -47,6 +47,7 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
char** values = NULL;
NCattribute* att = NULL;
if(ocname != NULL) free(ocname); /* from last loop */
OCCHECK(oc_dds_attr(conn,ocnode,j,&ocname,&ocetype,&nvalues,NULL));
if(nvalues > 0) {
values = (char**)malloc(sizeof(char*)*nvalues);
@ -104,6 +105,7 @@ fprintf(stderr,"%s.Unlimited_Dimension=%s\n",node->ocname,nccomm->cdf.recorddimn
}
done:
if(ocname != NULL) free(ocname);
if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat);
return THROW(ncstat);
}

View File

@ -8,16 +8,18 @@ PROG=./ncd
P=`pwd`
T="synth1"
T="synth4"
F="file://$TOP/ncdap_test/testdata3/$T"
#F="http://motherlode.ucar.edu:8081/dts/$T"
#F="http://motherlode.ucar.edu:8080/thredds/dodsC/testdods/coads_climatology.nc"
F="http://motherlode.ucar.edu:8080/thredds/dodsC/testdods/coads_climatology.nc"
#F="http://nomads.ncep.noaa.gov:9090/dods/gfs_hd/gfs_hd20120801/gfs_hd_00z"
VAR=lat
PARMS="[log]"
#PARMS="${PARMS}[netcdf3]"
#PARMS="${PARMS}[fetch=disk]"
PARMS="${PARMS}[cache]"
PARMS="${PARMS}[fetch=disk]"
#PARMS="${PARMS}[cache]"
#PARMS="${PARMS}[prefetch]"
#PARMS="${PARMS}[nocache]"
#PARMS="${PARMS}[noprefetch]"
@ -41,9 +43,6 @@ fi
U="${PARMS}$F"
if test "x$CON" != "x" ; then U="${PARMS}$F?$CON"; fi
UALL="${PARMS}$F"
if test "x${VAR}" != "x" ; then
ARGS="$ARGS -v ${VAR}"
fi
#ARGS="-h $ARGS"
#ARGS="-w $ARGS"
#ARGS="-c $ARGS"
@ -54,6 +53,7 @@ alias qq="gdb --args $PROG $ARGS '$U'"
alias qv="valgrind $VARGS PROG $ARGS '$U'"
alias q0="$PROG $ARGS '$U'"
alias qh="$PROG -h $ARGS '$U'"
alias qvar="$PROG -v $VAR $ARGS '$U'"
alias qqh="gdb --args $PROG -h $ARGS '$U'"
alias qall="$PROG -h $ARGS '${UALL}'"
alias qv="valgrind $VARGS $PROG $ARGS '$U'"

View File

@ -53,14 +53,11 @@ nc3dinitialize(void)
dap_zero[i] = 0;
}
nc3dinitialized = 1;
#if 0
/* This is causing a hang */
#ifdef DEBUG
/* force logging to go to stderr */
nclogclose();
nclogopen(NULL);
ncsetlogging(1); /* turn it on */
#endif
if(nclogopen(NULL))
ncsetlogging(1); /* turn it on */
#endif
return NC_NOERR;
}
@ -184,11 +181,11 @@ NCD3_open(const char * path, int mode,
/* Turn on logging; only do this after oc_open*/
if((value = paramvalue34(dapcomm,"log")) != NULL) {
ncloginit();
ncsetlogging(1);
nclogopen(value);
if(nclogopen(value))
ncsetlogging(1);
oc_loginit();
oc_setlogging(1);
oc_logopen(value);
if(oc_logopen(value))
oc_setlogging(1);
}
/* fetch and build the unconstrained DDS for use as
@ -308,6 +305,35 @@ fprintf(stderr,"ncdap3: final constraint: %s\n",dapcomm->oc.url->constraint);
ncstat = buildncstructures3(dapcomm);
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
/* Explicitly do not call enddef because it will complain
about variables that are too large.
*/
#if 0
ncstat = nc_endef(drno->substrate,NC_NOFILL,NULL);
if(ncstat != NC_NOERR && ncstat != NC_EVARSIZE)
{THROWCHK(ncstat); goto done;}
#endif
{
NC* ncsub;
NC* drno = dapcomm->controller;
CDFnode* unlimited = dapcomm->cdf.recorddim;
/* get the id for the substrate */
ncstat = NC_check_id(drno->substrate,&ncsub);
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
if(unlimited != NULL) {
/* Set the effective size of UNLIMITED;
note that this cannot easily be done thru the normal API.*/
NC_set_numrecs(ncsub,unlimited->dim.declsize);
}
/* Pretend the substrate is read-only */
NC_set_readonly(ncsub,1);
}
/* Do any necessary data prefetch */
if(FLAGSET(dapcomm->controls,NCF_PREFETCH)) {
ncstat = prefetchdata3(dapcomm);
@ -317,18 +343,6 @@ fprintf(stderr,"ncdap3: final constraint: %s\n",dapcomm->oc.url->constraint);
}
}
#ifdef BUG
/* The libsrc code (NC_begins) assumes that
a created files is new and hence must have an
unlimited dimension of 0 initially, which will
wipe out the effect of the NC_set_numrecs in builddims.
There is no easy workaround, so we suppress the call
to nc_enddef
*/
ncstat = nc_enddef(drno->substrate);
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
#endif
if(ncpp) *ncpp = (NC*)drno;
return ncstat;
@ -350,7 +364,10 @@ NCD3_close(int ncid)
if(ncstatus != NC_NOERR) return THROW(ncstatus);
dapcomm = (NCDAPCOMMON*)drno->dispatchdata;
ncstatus = nc_close(drno->substrate);
/* We call abort rather than close to avoid
trying to write anything or try to pad file length
*/
ncstatus = nc_abort(drno->substrate);
/* remove ourselves from NClist */
del_from_NCList(drno);
@ -429,9 +446,12 @@ builddims(NCDAPCOMMON* dapcomm)
ncstat = NC_check_id(drno->substrate,&ncsub);
if(ncstat != NC_NOERR) {THROWCHK(ncstat); goto done;}
#if 0
/* Set the effective size of UNLIMITED;
note that this cannot easily be done thru the normal API.*/
NC_set_numrecs(ncsub,unlimited->dim.declsize);
#endif
}
for(i=0;i<nclistlength(dimset);i++) {

View File

@ -38,6 +38,7 @@ freeNCDAPCOMMON(NCDAPCOMMON* dapcomm)
nclistfree(dapcomm->cdf.seqnodes);
nclistfree(dapcomm->cdf.gridnodes);
nclistfree(dapcomm->cdf.usertypes);
nclistfree(dapcomm->cdf.projectedvars);
nullfree(dapcomm->cdf.recorddimname);
/* free the trees */

View File

@ -33,16 +33,17 @@ static char* nctagname(int tag);
void
ncloginit(void)
{
const char* file = getenv(ENVFLAG);
ncinitlog = 1;
ncsetlogging(0);
nclogfile = NULL;
nclogstream = NULL;
/* Use environment variables to preset nclogging state*/
/* I hope this is portable*/
if(getenv(ENVFLAG) != NULL) {
const char* file = getenv(ENVFLAG);
ncsetlogging(1);
nclogopen(file);
if(file != NULL && strlen(file) > 0) {
if(nclogopen(file)) {
ncsetlogging(1);
}
}
nctagdfalt = NCTAGDFALT;
nctagset = nctagsetdfalt;
@ -55,7 +56,7 @@ ncsetlogging(int tf)
nclogging = tf;
}
void
int
nclogopen(const char* file)
{
if(!ncinitlog) ncloginit();
@ -89,9 +90,11 @@ nclogopen(const char* file)
nclogfile = NULL;
nclogstream = NULL;
ncsetlogging(0);
return 0;
}
ncsystemfile = 0;
}
return 1;
}
void

View File

@ -208,10 +208,11 @@ memio_create(const char* path, int ioflags,
return status;
memio->size = 0;
if(!persist) {
memio->memory = (char*)malloc(memio->alloc);
if(memio->memory == NULL) {status = NC_ENOMEM; goto unwind_open;}
} else { /*persist */
/* malloc memory */
memio->memory = (char*)malloc(memio->alloc);
if(memio->memory == NULL) {status = NC_ENOMEM; goto unwind_open;}
if(persist) {
/* Open the file, but make sure we can write it if needed */
oflags = (persist ? O_RDWR : O_RDONLY);
#ifdef O_BINARY
@ -228,9 +229,6 @@ memio_create(const char* path, int ioflags,
if(fd < 0) {status = errno; goto unwind_open;}
(void)close(fd); /* will reopen at nc_close */
/* malloc memory */
memio->memory = (char*)malloc(memio->alloc);
if(memio->memory == NULL) {status = NC_ENOMEM; goto unwind_open;}
} /*!persist*/
#ifdef DEBUG
@ -259,6 +257,8 @@ fprintf(stderr,"memio_create: initial memory: %lu/%lu\n",(unsigned long)memio->m
return NC_NOERR;
unwind_open:
if(memio->memory != NULL)
free(memio->memory);
memio_close(nciop,1);
return status;
}
@ -484,11 +484,11 @@ memio_close(ncio* nciop, int doUnlink)
}
} else
status = errno;
/* Free up things */
if(memio->memory != NULL) free(memio->memory);
}
done:
if(memio->memory != NULL)
free(memio->memory);
/* do cleanup */
if(fd >= 0) (void)close(fd);
if(memio != NULL) free(memio);

View File

@ -1557,3 +1557,19 @@ nc_delete(const char * path)
return nc_delete_mp(path, 0);
}
int
NC_set_readonly(NC *ncp, int tf)
{
int old = 1;
if(ncp != NULL && ncp->nciop != NULL) {
old = NC_readonly(ncp) ? 1 : 0;
old = fIsSet(ncp->nciop->ioflags, NC_WRITE) ? 0 : 1;
if(tf == 1) {
fClr(ncp->nciop->ioflags, NC_WRITE);
} else {/*tf==0*/
fSet(ncp->nciop->ioflags, NC_WRITE);
}
}
return old;
}

View File

@ -83,7 +83,7 @@ static char SccsId[] = "$Id: ncgen.y,v 1.34 2010/03/31 18:18:41 dmh Exp $";
#include "config.h"
#include <string.h>
#include <stdlib.h>
#include <netcdf.h>
#include "netcdf.h"
#include "generic.h"
#include "ncgen.h"
#include "genlib.h" /* for grow_darray() et al */

View File

@ -420,6 +420,7 @@ dap_parse_error(DAPparsestate* state, const char *fmt, ...)
(void) fprintf(stderr,"^%s\n",tmp);
(void) fflush(stderr); /* to ensure log files are current */
ocfree(tmp);
va_end(argv);
}
static void

View File

@ -180,13 +180,13 @@ a DAS, DDS, or DATADDS request exactly as sent by the server.
const char*
oc_tree_text(OCobject link, OCobject ddsroot)
{
OCnode* root;
OCnode* root = NULL;
OCVERIFYX(OC_Node,ddsroot,NULL);
OCDEREF(OCnode*,root,ddsroot);
if(root == NULL) return NULL;
root = root->root;
if(root == NULL) return NULL;
if(root->tree == NULL) return NULL;
return root->tree->text;
}

View File

@ -44,11 +44,11 @@ EXTERNC int ocbytescat(OCbytes*,const char*);
EXTERNC int ocbytessetcontents(OCbytes*, char*, unsigned int);
/* Following are always "in-lined"*/
#define ocbyteslength(bb) ((bb)?(bb)->length:0U)
#define ocbytesalloc(bb) ((bb)?(bb)->alloc:0U)
#define ocbytescontents(bb) ((bb && bb->content)?(bb)->content:(char*)"")
#define ocbyteslength(bb) ((bb)!=NULL?(bb)->length:0U)
#define ocbytesalloc(bb) ((bb)!=NULL?(bb)->alloc:0U)
#define ocbytescontents(bb) (((bb) !=NULL && (bb)->content != NULL)?(bb)->content:(char*)"")
#define ocbytesextend(bb,len) ocbytessetalloc((bb),(len)+(bb->alloc))
#define ocbytesclear(bb) ((bb)?(bb)->length=0:0U)
#define ocbytesavail(bb,n) ((bb)?((bb)->alloc - (bb)->length) >= (n):0U)
#define ocbytesclear(bb) ((bb)!=NULL?(bb)->length=0:0U)
#define ocbytesavail(bb,n) ((bb)!=NULL?((bb)->alloc - (bb)->length) >= (n):0U)
#endif /*OCBYTES_H*/

View File

@ -95,7 +95,7 @@ occompile1(OCstate* state, OCnode* xnode, XXDR* xxdrs, OCdata** datap)
fset(data->datamode,OCDT_ARRAY);
/* Determine # of instances */
nelements = octotaldimsize(xnode->array.rank,xnode->array.sizes);
if(nelements == 0) return OCTHROW(OC_ENODATA);
if(nelements == 0) {ocstat = OCTHROW(OC_ENODATA); goto fail;}
/* Validate and skip the leading count field */
if(!xxdr_uint(xxdrs,&xdrcount))
{ocstat = OC_EXDR; goto fail;}
@ -187,10 +187,10 @@ fail:
if(records != NULL) {
for(i=0;i<oclistlength(records);i++)
ocdata_free(state,(OCdata*)oclistget(records,i));
oclistfree(records);
}
if(data != NULL && data->instances != NULL) {
for(i=0;i<data->ninstances;i++)
ocdata_free(state,data->instances[i]);
if(data != NULL) {
ocdata_free(state,data);
}
return OCTHROW(ocstat);
}
@ -221,6 +221,7 @@ occompilefields(OCstate* state, OCdata* data, XXDR* xxdrs)
size_t nelements;
OCnode* xnode = data->template;
assert(data != NULL);
nelements = oclistlength(xnode->subnodes);
if(nelements == 0)
goto done;
@ -245,9 +246,10 @@ done:
return OCTHROW(ocstat);
fail:
if(data != NULL && data->instances != NULL) {
if(data->instances != NULL) {
for(i=0;i<data->ninstances;i++)
ocdata_free(state,data->instances[i]);
data->ninstances = 0;
}
return OCTHROW(ocstat);
}
@ -353,6 +355,7 @@ ocdata_free(OCstate* state, OCdata* data)
}
if(data->strings != NULL)
free(data->strings);
free(data);
}
static OCdata*

View File

@ -37,6 +37,7 @@
#define OCDBG2(l,msg,arg1,arg2) {oc_log(LOGDBG,msg,arg1,arg2);}
#define OCDBGTEXT(l,text) {oc_logtext(LOGNOTE,text);} else {}
#define OCDBGCODE(l,code) {code;}
#else
#define OCDBG(l,msg)
#define OCDBG1(l,msg,arg)

View File

@ -21,7 +21,7 @@
/* Note: TMPPATH must end in '/' */
#ifdef __CYGWIN__
#define TMPPATH1 "c:/temp/"
#define TMPPATH1 "/cygdrive/c/temp/"
#define TMPPATH2 "./"
#elif WIN32
#define TMPPATH1 "c:\\temp\\"
@ -208,7 +208,7 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
so that DRNO can reference it*/
/* Make the tmp file*/
stat = createtempfile(state,tree);
if(stat) {OCTHROWCHK(stat); goto unwind;}
if(stat) {OCTHROWCHK(stat); goto fail;}
stat = readDATADDS(state,tree,flags);
if(stat == OC_NOERR) {
/* Separate the DDS from data and return the dds;
@ -235,7 +235,7 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
} else {
oc_log(LOGWARN,"oc_open: Could not read url");
}
return OCTHROW(stat);
goto fail;
}
tree->nodes = NULL;
@ -246,7 +246,7 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
state->error.code,
(state->error.message?state->error.message:""));
}
if(stat) {OCTHROWCHK(stat); goto unwind;}
if(stat) {OCTHROWCHK(stat); goto fail;}
root = tree->root;
/* make sure */
tree->root = root;
@ -256,15 +256,15 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
switch (kind) {
case OCDAS:
if(root->octype != OC_Attributeset)
{OCTHROWCHK(stat=OC_EDAS); goto unwind;}
{OCTHROWCHK(stat=OC_EDAS); goto fail;}
break;
case OCDDS:
if(root->octype != OC_Dataset)
{OCTHROWCHK(stat=OC_EDDS); goto unwind;}
{OCTHROWCHK(stat=OC_EDDS); goto fail;}
break;
case OCDATADDS:
if(root->octype != OC_Dataset)
{OCTHROWCHK(stat=OC_EDATADDS); goto unwind;}
{OCTHROWCHK(stat=OC_EDATADDS); goto fail;}
/* Modify the tree kind */
tree->dxdclass = OCDATADDS;
break;
@ -293,7 +293,7 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
/* Compile the data into a more accessible format */
stat = occompile(state,tree->root);
if(stat != OC_NOERR)
goto unwind;
goto fail;
}
/* Put root into the state->trees list */
@ -302,16 +302,18 @@ ocfetch(OCstate* state, const char* constraint, OCdxd kind, OCflags flags,
if(rootp) *rootp = root;
return stat;
unwind:
octree_free(tree);
fail:
if(root != NULL)
ocroot_free(root);
else if(tree != NULL)
octree_free(tree);
return OCTHROW(stat);
}
static OCerror
createtempfile(OCstate* state, OCtree* tree)
{
int fd;
int fd = 0;
char* name = NULL;
fd = createtempfile1(TMPPATH1,&name);
if(fd < 0)
@ -334,7 +336,7 @@ createtempfile(OCstate* state, OCtree* tree)
int
createtempfile1(char* tmppath, char** tmpnamep)
{
int fd;
int fd = 0;
char* tmpname = NULL;
tmpname = (char*)malloc(strlen(tmppath)+strlen("dataddsXXXXXX")+1);
if(tmpname == NULL) return -1;
@ -354,7 +356,7 @@ createtempfile1(char* tmppath, char** tmpnamep)
sprintf(spid,"%06d",rno);
strcat(tmpname,spid);
# ifdef WIN32
fd=open(tmpname,O_RDWR|O_BINARY|O_CREAT|O_EXCL|_O_SHORT_LIVED, _S_IREAD|_S_IWRITE);
fd=open(tmpname,O_RDWR|O_BINARY|O_CREAT|O_EXCL|FILE_ATTRIBUTE_TEMPORARY, _S_IREAD|_S_IWRITE);
# else
fd=open(tmpname,O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
# endif

View File

@ -51,7 +51,7 @@ EXTERNC int oclistcontains(OClist*, ocelem);
#define oclistclear(l) oclistsetlength((l),0U)
#define oclistextend(l,len) oclistsetalloc((l),(len)+(l->alloc))
#define oclistcontents(l) ((l)->content)
#define oclistlength(l) ((l)?(l)->length:0U)
#define oclistlength(l) ((l!=NULL)?(l)->length:0U)
#endif /*OCLIST_H*/

View File

@ -32,9 +32,10 @@ oc_loginit(void)
oclogfile = NULL;
oclogstream = NULL;
/* Use environment variables to preset oclogging state*/
if(file != NULL) {
oc_setlogging(1);
oc_logopen(file);
if(file != NULL && strlen(file) > 0) {
if(oc_logopen(file)) {
oc_setlogging(1);
}
}
}
@ -76,6 +77,16 @@ oc_logopen(const char* file)
oclogstream = stderr;
oclogfile = NULL;
ocsystemfile = 1;
} else if(strcmp(file,"stdout") == 0) {
/* use stdout*/
oclogstream = stdout;
oclogfile = NULL;
ocsystemfile = 1;
} else if(strcmp(file,"stderr") == 0) {
/* use stderr*/
oclogstream = stderr;
oclogfile = NULL;
ocsystemfile = 1;
} else {
int fd;
oclogfile = (char*)malloc(strlen(file)+1);
@ -104,6 +115,7 @@ Logging is still enabled.
void
oc_logclose(void)
{
if(!ocloginit) oc_loginit();
if(oclogstream != NULL && !ocsystemfile) {
assert(oclogfile != NULL && oclogstream != NULL);
fclose(oclogstream);
@ -128,6 +140,8 @@ oc_log(int tag, const char* format, ...)
{
va_list args;
char* prefix;
if(!ocloginit) oc_loginit();
if(!oclogging || oclogstream == NULL) return;
switch (tag) {
@ -166,6 +180,7 @@ oc_logtext(int tag, const char* text)
size_t delta = 0;
const char* eol = text;
if(!ocloginit) oc_loginit();
if(!oclogging || oclogstream == NULL) return;
while(*text) {

View File

@ -143,7 +143,7 @@ makeattribute(char* name, OCtype ptype, OClist* values)
static void
marklostattribute(OCnode* att)
{
oc_log(LOGWARN,"Lost attribute: %s",att->name);
oc_log(LOGNOTE,"Lost attribute: %s",att->name);
}
void
@ -202,8 +202,12 @@ ocnodes_free(OClist* nodes)
while(oclistlength(node->attributes) > 0) {
OCattribute* attr = (OCattribute*)oclistpop(node->attributes);
ocfree(attr->name);
#if 0
/* If the attribute type is string, then we need to free them*/
if(attr->etype == OC_String || attr->etype == OC_URL) {
all values are strings now
if(attr->etype == OC_String || attr->etype == OC_URL)
#endif
{
char** strings = (char**)attr->values;
for(j=0;j<attr->nvalues;j++) {ocfree(*strings); strings++;}
}
@ -214,6 +218,7 @@ ocnodes_free(OClist* nodes)
if(node->subnodes != NULL) oclistfree(node->subnodes);
if(node->att.values != NULL) oclistfree(node->att.values);
if(node->attributes != NULL) oclistfree(node->attributes);
if(node->array.sizes != NULL) free(node->array.sizes);
ocfree(node);
}
oclistfree(nodes);
@ -236,9 +241,10 @@ As described there, the algorithm is as follows.
names to get each of those variables.
*/
int
OCerror
ocddsdasmerge(OCstate* state, OCnode* dasroot, OCnode* ddsroot)
{
OCerror stat = OC_NOERR;
OClist* dasglobals = oclistnew();
OClist* dodsglobals = oclistnew(); /* top-level DODS_XXX {...} */
OClist* dasnodes = oclistnew();
@ -247,10 +253,10 @@ ocddsdasmerge(OCstate* state, OCnode* dasroot, OCnode* ddsroot)
unsigned int i,j;
if(dasroot->tree == NULL || dasroot->tree->dxdclass != OCDAS)
return OCTHROW(OC_EINVAL);
{stat = OCTHROW(OC_EINVAL); goto done;}
if(ddsroot->tree == NULL || (ddsroot->tree->dxdclass != OCDDS
&& ddsroot->tree->dxdclass != OCDATADDS))
return OCTHROW(OC_EINVAL);
{stat = OCTHROW(OC_EINVAL); goto done;}
ddsnodes = ddsroot->tree->nodes;
@ -332,12 +338,14 @@ ocddsdasmerge(OCstate* state, OCnode* dasroot, OCnode* ddsroot)
OCnode* das = (OCnode*)oclistget(dodsglobals,i);
mergedods1(ddsroot,das);
}
done:
/* cleanup*/
oclistfree(dasglobals);
oclistfree(dodsglobals);
oclistfree(dasnodes);
oclistfree(varnodes);
return OCTHROW(OC_NOERR);
return OCTHROW(stat);
}
static int

View File

@ -193,7 +193,7 @@ readfile(const char* path, const char* suffix, OCbytes* packet)
stat = OC_NOERR;
for(;;) {
count = read(fd,buf,sizeof(buf));
if(count <= 0)
if(count == 0)
break;
else if(count < 0) {
stat = OC_EIO;

View File

@ -102,7 +102,7 @@ int
ocuriparse(const char* uri0, OCURI** ocurip)
{
OCURI* ocuri = NULL;
char* uri;
char* uri = NULL;
char** pp;
char* p;
char* p1;
@ -173,7 +173,8 @@ ocuriparse(const char* uri0, OCURI** ocurip)
/* locate the end of the host section */
file = strchr(p,'/');
/* Temporarily overwrite the '/' */
*file = '\0';
if(file != NULL)
*file = '\0';
/* extract any user:pwd */
host = p;
@ -189,22 +190,22 @@ ocuriparse(const char* uri0, OCURI** ocurip)
/* extract host and port */
p = host;
port = strchr(p,':');
if(port)
if(port!=NULL)
*port++ = '\0';
/* Locate end of the file */
constraint = strchr(file,'?');
if(constraint)
if(constraint!=NULL)
suffixparams = strchr(constraint,'#');
else
suffixparams = strchr(file,'#');
if(constraint) {
if(constraint != NULL) {
*constraint++ = '\0';
p = constraint;
}
if(suffixparams) {
if(suffixparams != NULL) {
*suffixparams++ = '\0';
p = suffixparams;
}
@ -302,7 +303,7 @@ ocurisetconstraints(OCURI* duri,const char* constraints)
char* select = NULL;
const char* p;
if(duri->constraint == NULL) free(duri->constraint);
if(duri->constraint != NULL) free(duri->constraint);
if(duri->projection != NULL) free(duri->projection);
if(duri->selection != NULL) free(duri->selection);
duri->constraint = NULL;

View File

@ -421,7 +421,7 @@ ocdataddsmsg(OCstate* state, OCtree* tree)
xxdr_setpos(xdrs,0);
/* read the whole thing */
contents = (char*)malloc(len+1);
xxdr_getbytes(xdrs,contents,len);
(void)xxdr_getbytes(xdrs,contents,len);
contents[len] = '\0';
/* Look for error tag */
for(i=0;i<len;i++) {
@ -542,7 +542,7 @@ ocdtmodestring(OCDT mode,int compact)
if(!compact && i > 0) strcat(result,",");
if(fisset(mode,(1<<i))) {
if(compact) *p++ = ms[0];
else strcat(result,ms);
else strncat(result,ms,sizeof(result));
}
}
/* pad compact list out to NMODES in length (+1 for null terminator) */