return error for NULL start for varm functions

This commit is contained in:
Ed Hartnett 2018-08-14 04:35:38 -06:00
parent a271ebb5f2
commit 5c39fa115a
3 changed files with 55 additions and 1 deletions

View File

@ -664,9 +664,18 @@ NC_get_varm(int ncid, int varid, const size_t *start,
void *value, nc_type memtype)
{
NC* ncp;
int rank;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
/* Non-scalar vars require start array. */
if(start == NULL) {
stat = nc_inq_varndims(ncid, varid, &rank);
if(stat != NC_NOERR) return stat;
if(rank > 0) return NC_EINVALCOORDS;
}
return ncp->dispatch->get_varm(ncid,varid,start,edges,stride,map,value,memtype);
}

View File

@ -563,7 +563,7 @@ NC_put_vars(int ncid, int varid, const size_t *start,
if(start == NULL) {
status = nc_inq_varndims(ncid, varid, &varndims);
if(status != NC_NOERR) return status;
if (varndims > 0) return NC_EINVALCOORDS;
if(varndims > 0) return NC_EINVALCOORDS;
}
return ncp->dispatch->put_vars(ncid,varid,start,edges,stride,value,memtype);
@ -578,9 +578,17 @@ NC_put_varm(int ncid, int varid, const size_t *start,
const void *value, nc_type memtype)
{
NC* ncp;
int varndims;
int status;
int stat = NC_check_id(ncid, &ncp);
if(stat != NC_NOERR) return stat;
/* Only scalar vars may have null starts. */
if(start == NULL) {
status = nc_inq_varndims(ncid, varid, &varndims);
if(status != NC_NOERR) return status;
if(varndims > 0) return NC_EINVALCOORDS;
}
return ncp->dispatch->put_varm(ncid,varid,start,edges,stride,map,value,memtype);
}

View File

@ -227,7 +227,18 @@ int main(int argc, char *argv[])
/* Open a netcdf-4 file, and one dimension. */
if (create_test_file(FILENAME, varid, &ncid)) ERR;
/* This will not work. */
if (nc_put_vara_uchar(ncid, varid[0], NULL, count, ubyte_data_out) !=
NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_put_vara_uchar(ncid, varid[0], start, count, ubyte_data_out)) ERR;
/* This will not work. */
if (nc_get_vara_uchar(ncid, varid[0], NULL, count, ubyte_data_in) !=
NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_get_vara_uchar(ncid, varid[0], start, count, ubyte_data_in)) ERR;
for (i = 0; i < SIZE; i++)
if (ubyte_data_in[i] != ubyte_data_out[i]) ERR;
@ -281,6 +292,11 @@ int main(int argc, char *argv[])
if (ubyte_data_in[0] != ubyte_data_out[0]) ERR;
if (ubyte_data_in[1] != ubyte_data_out[STRIDE_SIZE]) ERR;
/* This will not work. */
if (nc_put_vars_ushort(ncid, varid[1], NULL, count, stride,
ushort_data_out) != NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_put_vars_ushort(ncid, varid[1], start, count, stride,
ushort_data_out)) ERR;
if (nc_get_vars_ushort(ncid, varid[1], start, count, stride,
@ -323,7 +339,17 @@ int main(int argc, char *argv[])
/* Open a netcdf-4 file, and one dimension. */
if (create_test_file(FILENAME, varid, &ncid)) ERR;
/* This will not work. */
if (nc_put_var1_uchar(ncid, varid[0], NULL, ubyte_data_out) !=
NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_put_var1_uchar(ncid, varid[0], index1, ubyte_data_out)) ERR;
/* This will not work. */
if (nc_get_var1_uchar(ncid, varid[0], NULL, ubyte_data_in) != NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_get_var1_uchar(ncid, varid[0], index1, ubyte_data_in)) ERR;
if (ubyte_data_in[0] != ubyte_data_out[0]) ERR;
@ -361,8 +387,19 @@ int main(int argc, char *argv[])
/* Open a netcdf-4 file, and one dimension. */
if (create_test_file(FILENAME, varid, &ncid)) ERR;
/* This will not work. */
if (nc_put_varm_ubyte(ncid, varid[0], NULL, count, stride, imap,
ubyte_data_out) != NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_put_varm_ubyte(ncid, varid[0], start, count, stride, imap,
ubyte_data_out)) ERR;
/* This will not work. */
if (nc_get_varm_ubyte(ncid, varid[0], NULL, count, stride, imap,
ubyte_data_in) != NC_EINVALCOORDS) ERR;
/* This will work. */
if (nc_get_varm_ubyte(ncid, varid[0], start, count, stride, imap,
ubyte_data_in)) ERR;
for (i = 0; i < STRIDE_SIZE; i++)