fix some coverity complaints

This commit is contained in:
dmh 2014-04-07 13:00:47 -06:00
parent 2817f1e169
commit 389d2ea394
9 changed files with 23 additions and 11 deletions

View File

@ -342,6 +342,8 @@ NCcache*
createnccache(void)
{
NCcache* c = (NCcache*)calloc(1,sizeof(NCcache));
if(c == NULL)
return NULL;
c->cachelimit = DFALTCACHELIMIT;
c->cachesize = 0;
c->nodes = nclistnew();

View File

@ -597,7 +597,11 @@ dumpslices(DCEslice* slice, unsigned int rank)
buf = ncbytesnew();
for(i=0;i<rank;i++,slice++) {
ncbytescat(buf,dumpslice(slice));
String sslice = dumpslice(slice);
if(sslice != NULL) {
ncbytescat(buf,sslice);
free(sslice);
}
}
result = ncbytesdup(buf);
ncbytesfree(buf);

View File

@ -1412,9 +1412,10 @@ addstringdims(NCDAPCOMMON* dapcomm)
sdim = dapcomm->cdf.globalstringdim; /* use default */
else {
/* create a psuedo dimension for the charification of the string*/
if(var->dodsspecial.dimname != NULL)
if(var->dodsspecial.dimname != NULL) {
strncpy(dimname,var->dodsspecial.dimname,sizeof(dimname));
else
dimname[sizeof(dimname)-1] = '\0';
} else
snprintf(dimname,sizeof(dimname),"maxStrlen%lu",
(unsigned long)dimsize);
sdim = makecdfnode(dapcomm, dimname, OC_Dimension, NULL,

View File

@ -50,12 +50,12 @@ nclistfree(NClist* l)
int
nclistsetalloc(NClist* l, unsigned long sz)
{
void** newcontent;
void** newcontent = NULL;
if(l == NULL) return FALSE;
if(sz <= 0) {sz = (l->length?2*l->length:DEFAULTALLOC);}
if(l->alloc >= sz) {return TRUE;}
newcontent=(void**)calloc(sz,sizeof(void*));
if(l->alloc > 0 && l->length > 0 && l->content != NULL) {
if(newcontent != NULL && l->alloc > 0 && l->length > 0 && l->content != NULL) {
memcpy((void*)newcontent,(void*)l->content,sizeof(void*)*l->length);
}
if(l->content != NULL) free(l->content);

View File

@ -599,6 +599,8 @@ ncuridecodeparams(NCURI* ncuri)
/* plist is an env style list */
plist = (char**)calloc(1,sizeof(char*)*(2*nparams+1)); /* +1 for null termination */
if(plist == NULL)
return NC_ENOMEM;
/* Break up each param into a (name,value) pair*/
/* and insert into the param list */

View File

@ -50,12 +50,12 @@ listfree(List* l)
int
listsetalloc(List* l, unsigned long sz)
{
void** newcontent;
void** newcontent = NULL;
if(l == NULL) return FALSE;
if(sz <= 0) {sz = (l->length?2*l->length:DEFAULTALLOC);}
if(l->alloc >= sz) {return TRUE;}
newcontent=(void**)calloc(sz,sizeof(void*));
if(l->alloc > 0 && l->length > 0 && l->content != NULL) {
if(newcontent != NULL && l->alloc > 0 && l->length > 0 && l->content != NULL) {
memcpy((void*)newcontent,(void*)l->content,sizeof(void*)*l->length);
}
if(l->content != NULL) free(l->content);

View File

@ -50,12 +50,12 @@ oclistfree(OClist* l)
int
oclistsetalloc(OClist* l, size_t sz)
{
void** newcontent;
void** newcontent = NULL;
if(l == NULL) return FALSE;
if(sz <= 0) {sz = (l->length?2*l->length:DEFAULTALLOC);}
if(l->alloc >= sz) {return TRUE;}
newcontent=(void**)calloc(sz,sizeof(void*));
if(l->alloc > 0 && l->length > 0 && l->content != NULL) {
if(newcontent != NULL && l->alloc > 0 && l->length > 0 && l->content != NULL) {
memcpy((void*)newcontent,(void*)l->content,sizeof(void*)*l->length);
}
if(l->content != NULL) free(l->content);
@ -147,7 +147,8 @@ void**
oclistdup(OClist* l)
{
void** result = (void**)malloc(sizeof(void*)*(l->length+1));
memcpy((void*)result,(void*)l->content,sizeof(void*)*l->length);
if(result != NULL && l != NULL && oclistength(l) != 0)
memcpy((void*)result,(void*)l->content,sizeof(void*)*l->length);
result[l->length] = (void*)0;
return result;
}

View File

@ -598,6 +598,8 @@ ocuridecodeparams(OCURI* ocuri)
/* plist is an env style list */
plist = (char**)calloc(1,sizeof(char*)*(2*nparams+1)); /* +1 for null termination */
if(plist == NULL)
return NC_ENOMEM;
/* Break up each param into a (name,value) pair*/
/* and insert into the param list */

2
wjna
View File

@ -20,7 +20,7 @@ FLAGS="-DENABLE_EXAMPLES=OFF ${FLAGS}"
rm -fr ./build
mkdir build
pushd build
cmake -G"Visual Studio 10" ${FLAGS} ..
cmake -G"Visual Studio 8" ${FLAGS} ..
cmake --build . --config Release
cmake --build . --target INSTALL
popd