mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-04-24 18:30:51 +08:00
Coverity: 1302444, addressed a potential negative argument being passed to memory allocation routine.
This commit is contained in:
parent
f1d2470776
commit
720fe78ea2
@ -97,9 +97,8 @@ static int memio_close(ncio* nciop, int);
|
||||
|
||||
static long pagesize = 0;
|
||||
|
||||
/* Create a new ncio struct to hold info about the file. */
|
||||
static int
|
||||
memio_new(const char* path, int ioflags, off_t initialsize, void* memory, ncio** nciopp, NCMEMIO** memiop)
|
||||
/*! Create a new ncio struct to hold info about the file. */
|
||||
static int memio_new(const char* path, int ioflags, off_t initialsize, void* memory, ncio** nciopp, NCMEMIO** memiop)
|
||||
{
|
||||
int status = NC_NOERR;
|
||||
ncio* nciop = NULL;
|
||||
@ -126,6 +125,14 @@ memio_new(const char* path, int ioflags, off_t initialsize, void* memory, ncio**
|
||||
#endif
|
||||
}
|
||||
|
||||
/* We need to catch errors.
|
||||
sysconf, at least, can return a negative value
|
||||
when there is an error. */
|
||||
if(pagesize < 0) {
|
||||
status = NC_EIO;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
|
||||
/* Always force the allocated size to be a multiple of pagesize */
|
||||
@ -165,7 +172,7 @@ memio_new(const char* path, int ioflags, off_t initialsize, void* memory, ncio**
|
||||
free(nciop);
|
||||
}
|
||||
if(inmemory) {
|
||||
memio->memory = memory;
|
||||
memio->memory = memory;
|
||||
} else {
|
||||
/* malloc memory */
|
||||
memio->memory = (char*)malloc(memio->alloc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user