mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-12 15:45:21 +08:00
Took some time to address a handful of errors identified by Coverity.
Primarily focused on memory errors falling into a couple different types: 1) Static overrun errors. 2) Dereference uninitialized memory errors. make distcheck works after applying these fixes, and coverity no longer sees an issue, so hopefully they are properly resolved.
This commit is contained in:
parent
3232c1182c
commit
afa67452f6
@ -47,7 +47,10 @@ dapmerge3(NCDAPCOMMON* nccomm, CDFnode* ddsroot, OCddsnode dasroot)
|
||||
char** values = NULL;
|
||||
NCattribute* att = NULL;
|
||||
|
||||
if(ocname != NULL) free(ocname); /* from last loop */
|
||||
if(ocname != NULL) {
|
||||
free(ocname); ocname = NULL;
|
||||
} /* from last loop */
|
||||
|
||||
OCCHECK(oc_dds_attr(conn,ocnode,j,&ocname,&ocetype,&nvalues,NULL));
|
||||
if(nvalues > 0) {
|
||||
values = (char**)malloc(sizeof(char*)*nvalues);
|
||||
|
@ -284,7 +284,7 @@ memio_open(const char* path,
|
||||
off_t igeto, size_t igetsz, size_t* sizehintp,
|
||||
ncio* *nciopp, void** const mempp)
|
||||
{
|
||||
ncio* nciop;
|
||||
ncio* nciop = NULL;
|
||||
int fd;
|
||||
int status;
|
||||
int persist = (fIsSet(ioflags,NC_WRITE)?1:0);
|
||||
@ -377,6 +377,7 @@ fprintf(stderr,"memio_open: initial memory: %lu/%lu\n",(unsigned long)memio->mem
|
||||
return NC_NOERR;
|
||||
|
||||
unwind_open:
|
||||
|
||||
memio_close(nciop,0);
|
||||
return status;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ nc4_create_file(const char *path, int cmode, MPI_Comm comm, MPI_Info info,
|
||||
FILE *fp;
|
||||
int retval = NC_NOERR;
|
||||
int persist = 0; /* Should diskless try to persist its data into file?*/
|
||||
NC_HDF5_FILE_INFO_T* nc4_info;
|
||||
NC_HDF5_FILE_INFO_T* nc4_info = NULL;
|
||||
|
||||
|
||||
assert(nc);
|
||||
@ -336,6 +336,7 @@ nc4_create_file(const char *path, int cmode, MPI_Comm comm, MPI_Info info,
|
||||
return NC_NOERR;
|
||||
|
||||
exit:
|
||||
if(!nc4_info) return retval;
|
||||
if (nc4_info->hdfid > 0) H5Fclose(nc4_info->hdfid);
|
||||
return retval;
|
||||
}
|
||||
@ -2200,7 +2201,7 @@ nc4_open_file(const char *path, int mode, MPI_Comm comm,
|
||||
unsigned flags = (mode & NC_WRITE) ?
|
||||
H5F_ACC_RDWR : H5F_ACC_RDONLY;
|
||||
int retval;
|
||||
NC_HDF5_FILE_INFO_T* nc4_info;
|
||||
NC_HDF5_FILE_INFO_T* nc4_info = NULL;
|
||||
|
||||
LOG((3, "nc4_open_file: path %s mode %d", path, mode));
|
||||
assert(path && nc);
|
||||
@ -2301,6 +2302,7 @@ nc4_open_file(const char *path, int mode, MPI_Comm comm,
|
||||
#ifdef EXTRA_TESTS
|
||||
num_plists--;
|
||||
#endif
|
||||
if (!nc4_info) return retval;
|
||||
if (nc4_info->hdfid > 0) H5Fclose(nc4_info->hdfid);
|
||||
if (nc4_info) free(nc4_info);
|
||||
return retval;
|
||||
|
@ -272,12 +272,12 @@ NC4_inq_type(int ncid, nc_type typeid, char *name, size_t *size)
|
||||
LOG((2, "nc_inq_type: ncid 0x%x typeid %d", ncid, typeid));
|
||||
|
||||
/* If this is an atomic type, the answer is easy. */
|
||||
if (typeid <= NUM_ATOMIC_TYPES)
|
||||
if (typeid < NUM_ATOMIC_TYPES)
|
||||
{
|
||||
if (name)
|
||||
strcpy(name, atomic_name[typeid]);
|
||||
strcpy(name, atomic_name[typeid]);
|
||||
if (size)
|
||||
*size = atomic_size[typeid];
|
||||
*size = atomic_size[typeid];
|
||||
return NC_NOERR;
|
||||
}
|
||||
|
||||
|
11
ncgen/util.c
11
ncgen/util.c
@ -517,11 +517,12 @@ dlappend(Datalist* dl, Constant* constant)
|
||||
Constant
|
||||
builddatasublist(Datalist* dl)
|
||||
{
|
||||
Constant d;
|
||||
d.nctype = NC_COMPOUND;
|
||||
d.lineno = (dl->length > 0?dl->data[0].lineno:0);
|
||||
d.value.compoundv = dl;
|
||||
return d;
|
||||
Constant d;
|
||||
d.nctype = NC_COMPOUND;
|
||||
d.lineno = (dl->length > 0?dl->data[0].lineno:0);
|
||||
d.value.compoundv = dl;
|
||||
d.filled = NULL;
|
||||
return d;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -298,7 +298,7 @@ dumpfield(int index, char* n8, int isxdr)
|
||||
sprintf(stmp,"\\%02x",c);
|
||||
else
|
||||
sprintf(stmp,"%c",c);
|
||||
strcat(tmp,stmp);
|
||||
strncat(tmp,stmp,4);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 strncat(result,ms,sizeof(result));
|
||||
else strncat(result,ms,sizeof(result)-1);
|
||||
}
|
||||
}
|
||||
/* pad compact list out to NMODES in length (+1 for null terminator) */
|
||||
|
Loading…
Reference in New Issue
Block a user