From 68a57832d6907183483f58eed0f93963ec21bd14 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Mon, 3 Apr 2017 22:07:36 -0500 Subject: [PATCH 1/2] enable nc_open to check the number of large variables allowed in CDF-1 and CDF-2 files --- include/nc3internal.h | 3 +++ libsrc/nc3internal.c | 2 +- libsrc/v1hpg.c | 4 ++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/nc3internal.h b/include/nc3internal.h index a9b2d8124..42059d887 100644 --- a/include/nc3internal.h +++ b/include/nc3internal.h @@ -418,6 +418,9 @@ nc_put_rec(int ncid, size_t recnum, void *const *datap); /* End defined in putget.c */ +extern int +NC_check_vlens(NC3_INFO *ncp); + /* Define accessors for the dispatchdata */ #define NC3_DATA(nc) ((NC3_INFO*)(nc)->dispatchdata) #define NC3_DATA_SET(nc,data) ((nc)->dispatchdata = (void*)(data)) diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 13e83ced4..571835f83 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -680,7 +680,7 @@ move_vars_r(NC3_INFO *gnu, NC3_INFO *old) * Given a valid ncp, return NC_EVARSIZE if any variable has a bad len * (product of non-rec dim sizes too large), else return NC_NOERR. */ -static int +int NC_check_vlens(NC3_INFO *ncp) { NC_var **vpp; diff --git a/libsrc/v1hpg.c b/libsrc/v1hpg.c index afdeb519a..a5cee4fda 100644 --- a/libsrc/v1hpg.c +++ b/libsrc/v1hpg.c @@ -1520,6 +1520,10 @@ nc_get_NC(NC3_INFO* ncp) if(status != NC_NOERR) goto unwind_get; + status = NC_check_vlens(ncp); + if(status != NC_NOERR) + goto unwind_get; + unwind_get: (void) rel_v1hs(&gs); return status; From 1af2643fb8c2cf9b478e61260f42e3ee6ddd9df2 Mon Sep 17 00:00:00 2001 From: Wei-keng Liao Date: Mon, 3 Apr 2017 22:17:36 -0500 Subject: [PATCH 2/2] rename macro ERR to ERR_CHK, as ERR is already defined in err_macros.h --- nc_test/tst_elatefill.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/nc_test/tst_elatefill.c b/nc_test/tst_elatefill.c index 3f2099f92..0b9ca6aa0 100644 --- a/nc_test/tst_elatefill.c +++ b/nc_test/tst_elatefill.c @@ -20,7 +20,7 @@ #define FILE_NAME "tst_elatefill.nc" -#define ERR {if(err!=NC_NOERR)printf("Error at line %d: %s\n",__LINE__,nc_strerror(err));} +#define ERR_CHK {if(err!=NC_NOERR)printf("Error at line %d: %s\n",__LINE__,nc_strerror(err));} int main(int argc, char **argv) @@ -28,18 +28,18 @@ main(int argc, char **argv) int ncid, dimid, varid, err; int no_fill, fillv, buf[10]; - err = nc_create(FILE_NAME, NC_NETCDF4, &ncid); ERR; - err = nc_def_dim(ncid, "dim", 10, &dimid); ERR; - err = nc_def_var(ncid, "var", NC_INT, 1, &dimid, &varid); ERR; - err = nc_enddef(ncid); ERR; + err = nc_create(FILE_NAME, NC_NETCDF4, &ncid); ERR_CHK; + err = nc_def_dim(ncid, "dim", 10, &dimid); ERR_CHK; + err = nc_def_var(ncid, "var", NC_INT, 1, &dimid, &varid); ERR_CHK; + err = nc_enddef(ncid); ERR_CHK; - err = nc_redef(ncid); ERR; + err = nc_redef(ncid); ERR_CHK; /* try put attribute _FillValue and expect NC_ELATEFILL */ fillv = 9; err = nc_put_att_int(ncid, varid, _FillValue, NC_INT, 1, &fillv); if (err != NC_ELATEFILL) printf("line %d expecting NC_ELATEFILL but got %d\n",__LINE__,err); - err = nc_close(ncid); ERR; + err = nc_close(ncid); ERR_CHK; return 0; }