mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-25 17:40:27 +08:00
fix some coverity complaints
This commit is contained in:
parent
2817f1e169
commit
389d2ea394
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
|
@ -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 */
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user