mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-21 03:13:42 +08:00
Addressed a handful of issues reported by Coverity static analysis.
This commit is contained in:
parent
63d59cc9e9
commit
cc56035d44
@ -186,16 +186,18 @@ fprintf(stderr,"\n");
|
||||
|
||||
/* Validate the dimension sizes */
|
||||
for(i=0;i<ncrank;i++) {
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdimsall,i);
|
||||
if(startp[i] < 0 || countp[i] < 0 || stridep[i] < 1) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
if(startp[i] >= dim->dim.declsize
|
||||
|| startp[i]+(stridep[i]*(countp[i]-1)) >= dim->dim.declsize) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
CDFnode* dim = (CDFnode*)nclistget(ncdimsall,i);
|
||||
/* countp and startp are unsigned, so will never be < 0 */
|
||||
//if(startp[i] < 0 || countp[i] < 0 || stridep[i] < 1) {
|
||||
if(stridep[i] < 1) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
if(startp[i] >= dim->dim.declsize
|
||||
|| startp[i]+(stridep[i]*(countp[i]-1)) >= dim->dim.declsize) {
|
||||
ncstat = NC_EINVALCOORDS;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
|
@ -341,6 +341,10 @@ nc_copy_var(int ncid_in, int varid_in, int ncid_out)
|
||||
if (!(dimlen = malloc(real_ndims * sizeof(size_t))))
|
||||
BAIL(NC_ENOMEM);
|
||||
|
||||
/* Set to 0, to correct for an unlikely dereference
|
||||
error reported by clang/llvm. */
|
||||
dimlen[0] = 0;
|
||||
|
||||
/* Find out how much data. */
|
||||
for (d=0; d<ndims; d++)
|
||||
{
|
||||
|
@ -199,10 +199,14 @@ NCDEFAULT_get_vars(int ncid, int varid, const size_t * start,
|
||||
if(mystride[i] != 1) simplestride = 0;
|
||||
/* illegal value checks */
|
||||
dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
|
||||
if(mystart < 0 || mystart[i] >= dimlen)
|
||||
return NC_EINVALCOORDS;
|
||||
if(myedges[i] < 0 || (mystart[i] + myedges[i] > dimlen))
|
||||
return NC_EEDGE;
|
||||
/* mystart is unsigned, never < 0 */
|
||||
//if(mystart[i] < 0 || mystart[i] >= dimlen)
|
||||
if(mystart[i] >= dimlen)
|
||||
return NC_EINVALCOORDS;
|
||||
/* myedges is unsigned, never < 0 */
|
||||
//if(myedges[i] < 0 || (mystart[i] + myedges[i] > dimlen))
|
||||
if(mystart[i] + myedges[i] > dimlen)
|
||||
return NC_EEDGE;
|
||||
}
|
||||
if(simplestride) {
|
||||
return NC_get_vara(ncid, varid, mystart, myedges, value, memtype);
|
||||
|
@ -207,10 +207,14 @@ NCDEFAULT_put_vars(int ncid, int varid, const size_t * start,
|
||||
dimlen = (i == 0 && isrecvar ? numrecs : varshape[i]);
|
||||
if(i == 0 && isrecvar) {/*do nothing*/}
|
||||
else {
|
||||
if(mystart[i] < 0 || mystart[i] > dimlen)
|
||||
return NC_EINVALCOORDS;
|
||||
if(myedges[i] < 0 || (mystart[i] + myedges[i] > dimlen))
|
||||
return NC_EEDGE;
|
||||
/* mystart is unsigned, will never be < 0 */
|
||||
//if(mystart[i] < 0 || mystart[i] > dimlen)
|
||||
if(mystart[i] > dimlen)
|
||||
return NC_EINVALCOORDS;
|
||||
/* myediges is unsigned, will never be < 0 */
|
||||
//if(myedges[i] < 0 || (mystart[i] + myedges[i] > dimlen))
|
||||
if(mystart[i] + myedges[i] > dimlen)
|
||||
return NC_EEDGE;
|
||||
}
|
||||
}
|
||||
if(simplestride) {
|
||||
|
@ -295,6 +295,7 @@ ncuriparse(const char* uri0, NCURI** durip)
|
||||
}
|
||||
|
||||
/* do last minute empty check */
|
||||
|
||||
if(protocol != NULL && *protocol == EOFCHAR) protocol = NULL;
|
||||
if(user != NULL && *user == EOFCHAR) user = NULL;
|
||||
if(pwd != NULL && *pwd == EOFCHAR) pwd = NULL;
|
||||
|
@ -216,7 +216,7 @@ static int
|
||||
nc4_create_file(const char *path, int cmode, MPI_Comm comm, MPI_Info info,
|
||||
NC *nc)
|
||||
{
|
||||
hid_t fcpl_id, fapl_id;
|
||||
hid_t fcpl_id, fapl_id = -1;
|
||||
unsigned flags;
|
||||
FILE *fp;
|
||||
int retval = NC_NOERR;
|
||||
|
3
oc2/oc.c
3
oc2/oc.c
@ -987,6 +987,9 @@ oc_data_fieldbyname(OCobject link, OCobject datanode, const char* name, OCobject
|
||||
// Get the field's name
|
||||
err = oc_dds_name(link,field,&fieldname);
|
||||
if(err != OC_NOERR) return err;
|
||||
if(!fieldname)
|
||||
return OC_EINVAL;
|
||||
|
||||
match = strcmp(name,fieldname);
|
||||
if(fieldname != NULL) free(fieldname);
|
||||
if(match == 0) {
|
||||
|
@ -107,8 +107,10 @@ ocinternalinitialize(void)
|
||||
size_t pathlen = strlen(homepath)+1+strlen(*alias)+1;
|
||||
path = (char*)malloc(pathlen);
|
||||
if(path == NULL) return OC_ENOMEM;
|
||||
if(!occopycat(path,pathlen,3,homepath,"/",*alias))
|
||||
return OC_EOVERRUN;
|
||||
if(!occopycat(path,pathlen,3,homepath,"/",*alias)) {
|
||||
if(path) {free(path);}
|
||||
return OC_EOVERRUN;
|
||||
}
|
||||
f = fopen(path,"r");
|
||||
if(f != NULL) break;
|
||||
if(path != NULL) {free(path); path=NULL;}
|
||||
@ -587,7 +589,9 @@ ocsetcurlproperties(OCstate* state)
|
||||
size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1;
|
||||
char* agent = (char*)malloc(len+1);
|
||||
if(occopycat(agent,len,2,DFALTUSERAGENT,VERSION))
|
||||
state->curlflags.useragent = agent;
|
||||
state->curlflags.useragent = agent;
|
||||
else
|
||||
free(agent);
|
||||
}
|
||||
return;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user