diff --git a/libdap2/dapdump.c b/libdap2/dapdump.c index e66ea3db9..9c80054d0 100644 --- a/libdap2/dapdump.c +++ b/libdap2/dapdump.c @@ -156,10 +156,10 @@ dumpdata1(nc_type nctype, size_t index, char* data) fprintf(stdout,"'%c' %hhd",data[index],data[index]); break; case NC_BYTE: - fprintf(stdout,"%hdB",((signed char*)data)[index]); + fprintf(stdout,"%hhdB",((signed char*)data)[index]); break; case NC_UBYTE: - fprintf(stdout,"%huB",((unsigned char*)data)[index]); + fprintf(stdout,"%hhuB",((unsigned char*)data)[index]); break; case NC_SHORT: fprintf(stdout,"%hdS",((short*)data)[index]); diff --git a/libdap4/d4parser.c b/libdap4/d4parser.c index 2cbe43044..06289c710 100644 --- a/libdap4/d4parser.c +++ b/libdap4/d4parser.c @@ -525,7 +525,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n vlentype->basetype = var->basetype; /* Use name _t */ strncpy(name,fqnname,sizeof(name)); - strlcat(name,"_t",sizeof(name)); + strncat(name,"_t", sizeof(name) - strlen(name) - 1); SETNAME(vlentype,name); /* Set the basetype */ var->basetype = vlentype; @@ -540,7 +540,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n classify(group,structtype); /* Use name _base */ strncpy(name,fqnname,sizeof(name)); - strlcat(name,"_base",sizeof(name)); + strncat(name,"_base", sizeof(name) - strlen(name) - 1); SETNAME(structtype,name); /* Parse Fields into type */ if((ret = parseFields(parser,structtype,xml))) goto done; @@ -549,7 +549,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n classify(group,vlentype); /* Use name _t */ strncpy(name,fqnname,sizeof(name)); - strlcat(name,"_t",sizeof(name)); + strncat(name,"_t", sizeof(name) - strlen(name) - 1); SETNAME(vlentype,name); vlentype->basetype = structtype; /* Set the basetype */ diff --git a/libdap4/d4util.c b/libdap4/d4util.c index c5a2b5470..d2e83f6eb 100644 --- a/libdap4/d4util.c +++ b/libdap4/d4util.c @@ -328,6 +328,101 @@ NCD4_entityescape(const char* s) return escaped; } +int +NCD4_readfile(const char* filename, NCbytes* content) +{ + int ret = NC_NOERR; + FILE* stream = NULL; + char part[1024]; + + stream = fopen(filename,"r"); + if(stream == NULL) {ret=errno; goto done;} + for(;;) { + size_t count = fread(part, 1, sizeof(part), stream); + if(count <= 0) break; + ncbytesappendn(content,part,count); + if(ferror(stream)) {ret = NC_EIO; goto done;} + if(feof(stream)) break; + } + ncbytesnull(content); +done: + if(stream) fclose(stream); + return ret; +} + +/** +Wrap mktmp and return the generated name +*/ + +int +NCD4_mktmp(const char* base, char** tmpnamep) +{ + int fd; + char tmp[NC_MAX_PATH]; +#ifdef HAVE_MKSTEMP + mode_t mask; +#endif + + strncpy(tmp,base,sizeof(tmp)); +#ifdef HAVE_MKSTEMP + strncat(tmp,"XXXXXX", sizeof(tmp) - strlen(tmp) - 1); + /* Note Potential problem: old versions of this function + leave the file in mode 0666 instead of 0600 */ + mask=umask(0077); + fd = mkstemp(tmp); + (void)umask(mask); +#else /* !HAVE_MKSTEMP */ + /* Need to simulate by using some kind of pseudo-random number */ + { + int rno = rand(); + char spid[7]; + if(rno < 0) rno = -rno; + snprintf(spid,sizeof(spid),"%06d",rno); + strncat(tmp,spid,sizeof(tmp)); +#if defined(_WIN32) || defined(_WIN64) + fd=open(tmp,O_RDWR|O_BINARY|O_CREAT, _S_IREAD|_S_IWRITE); +# else + fd=open(tmp,O_RDWR|O_CREAT|O_EXCL, S_IRWXU); +# endif + } +#endif /* !HAVE_MKSTEMP */ + if(fd < 0) { + nclog(NCLOGERR, "Could not create temp file: %s",tmp); + return THROW(NC_EPERM); + } else + close(fd); + if(tmpnamep) *tmpnamep = strdup(tmp); + return THROW(NC_NOERR); +} + +void +NCD4_hostport(NCURI* uri, char* space, size_t len) +{ + if(space != NULL && len > 0) { + space[0] = '\0'; /* so we can use strncat */ + if(uri->host != NULL) { + strncat(space,uri->host,len); + if(uri->port != NULL) { + strncat(space,":",len); + strncat(space,uri->port,len); + } + } + } +} + +void +NCD4_userpwd(NCURI* uri, char* space, size_t len) +{ + if(space != NULL && len > 0) { + space[0] = '\0'; /* so we can use strncat */ + if(uri->user != NULL && uri->password != NULL) { + strncat(space,uri->user,len); + strncat(space,":",len); + strncat(space,uri->password,len); + } + } +} + #ifdef BLOB void NCD4_saveblob(NCD4meta* meta, void* mem) diff --git a/libdispatch/dv2i.c b/libdispatch/dv2i.c index 5d4123803..c7c05a96d 100644 --- a/libdispatch/dv2i.c +++ b/libdispatch/dv2i.c @@ -12,7 +12,7 @@ See \ref copyright file for copying and redistribution conditions. #include #include #include "netcdf.h" -#include "math.h" +#include /** \defgroup v2_api The Version 2 API diff --git a/libsrc/nc3internal.c b/libsrc/nc3internal.c index 1705b04f7..88eb83ae5 100644 --- a/libsrc/nc3internal.c +++ b/libsrc/nc3internal.c @@ -158,6 +158,7 @@ NC_begins(NC3_INFO* ncp, size_t ii, j; int sizeof_off_t; off_t index = 0; + off_t old_ncp_begin_var; NC_var **vpp; NC_var *last = NULL; NC_var *first_var = NULL; /* first "non-record" var */ @@ -179,6 +180,8 @@ NC_begins(NC3_INFO* ncp, if(ncp->vars.nelems == 0) return NC_NOERR; + old_ncp_begin_var = ncp->begin_var; + /* only (re)calculate begin_var if there is not sufficient space in header or start of non-record variables is not aligned as requested by valign */ if (ncp->begin_var < ncp->xsz + h_minfree || @@ -217,6 +220,7 @@ fprintf(stderr, " VAR %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index); #endif if( sizeof_off_t == 4 && (index > X_OFF_MAX || index < 0) ) { + ncp->begin_var = old_ncp_begin_var; return NC_EVARSIZE; } (*vpp)->begin = index; @@ -287,6 +291,7 @@ fprintf(stderr, " REC %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index); #endif if( sizeof_off_t == 4 && (index > X_OFF_MAX || index < 0) ) { + ncp->begin_var = old_ncp_begin_var; return NC_EVARSIZE; } (*vpp)->begin = index; @@ -309,6 +314,7 @@ fprintf(stderr, " REC %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index); #if SIZEOF_OFF_T == SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4 if( ncp->recsize > X_UINT_MAX - (*vpp)->len ) { + ncp->begin_var = old_ncp_begin_var; return NC_EVARSIZE; } #endif diff --git a/libsrc4/nc4file.c b/libsrc4/nc4file.c index 225f6a708..e689f4521 100644 --- a/libsrc4/nc4file.c +++ b/libsrc4/nc4file.c @@ -997,7 +997,11 @@ nc4_create_file(const char *path, int cmode, MPI_Comm comm, MPI_Info info, #endif /* USE_PARALLEL4 */ #ifdef HDF5_HAS_LIBVER_BOUNDS +#if H5_VERSION_GE(1,10,2) + if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_EARLIEST, H5F_LIBVER_V18) < 0) +#else if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_EARLIEST, H5F_LIBVER_LATEST) < 0) +#endif BAIL(NC_EHDFERR); #endif diff --git a/nc_test/CMakeLists.txt b/nc_test/CMakeLists.txt index 06943c5c8..fb6e063a8 100644 --- a/nc_test/CMakeLists.txt +++ b/nc_test/CMakeLists.txt @@ -30,7 +30,7 @@ TARGET_LINK_LIBRARIES(nc_test ) # Some extra stand-alone tests -SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill) +SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef) IF(NOT HAVE_BASH) SET(TESTS ${TESTS} tst_atts3) diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am index a49d3d409..a45346afc 100644 --- a/nc_test/Makefile.am +++ b/nc_test/Makefile.am @@ -19,7 +19,7 @@ TEST_EXTENSIONS = .sh TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm tst_names \ tst_nofill tst_nofill2 tst_nofill3 tst_atts3 tst_meta tst_inq_type \ tst_utf8_validate tst_utf8_phrases tst_global_fillval \ -tst_max_var_dims tst_formats tst_def_var_fill +tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef if USE_NETCDF4 TESTPROGRAMS += tst_atts tst_put_vars tst_elatefill diff --git a/nc_test/tst_err_enddef.c b/nc_test/tst_err_enddef.c new file mode 100644 index 000000000..7d0f9f6cd --- /dev/null +++ b/nc_test/tst_err_enddef.c @@ -0,0 +1,52 @@ +#include +#include + +#define CHECK_ERR { \ + if (err != NC_NOERR) { \ + nerrs++; \ + printf("Error at line %d in %s: (%s)\n", \ + __LINE__,__FILE__,nc_strerror(err)); \ + } \ +} + +#define EXP_ERR(exp) { \ + if (err != exp) { \ + nerrs++; \ + printf("Error at line %d in %s: expecting %s but got %s\n", \ + __LINE__,__FILE__,nc_strerror(exp), nc_strerror(err)); \ + } \ +} + +int main(int argc, char** argv) +{ + char *filename="tst_err_enddef.nc"; + int err, nerrs=0, ncid, cmode, varid, dimid[3]; + + if (argc == 2) filename = argv[1]; + printf("*** TESTING error code returned from nc__enddef and nc_close "); + + cmode = NC_CLOBBER; + err = nc_create(filename, cmode, &ncid); CHECK_ERR + err = nc_set_fill(ncid, NC_NOFILL, NULL); CHECK_ERR + + err = nc_def_dim(ncid, "X", 5, &dimid[0]); CHECK_ERR + err = nc_def_dim(ncid, "YY", 32000, &dimid[1]); CHECK_ERR + err = nc_def_dim(ncid, "XX", 32000, &dimid[2]); CHECK_ERR + + err = nc_def_var(ncid, "var", NC_INT, 1, dimid, &varid); CHECK_ERR + err = nc_def_var(ncid, "var_big", NC_FLOAT, 2, dimid+1, &varid); CHECK_ERR + + /* make the file header size larger than 2 GiB */ + err = nc__enddef(ncid, 2147483648LL, 1, 1, 1); + EXP_ERR(NC_EVARSIZE) + + /* the above error keeps the program in define mode, thus close will + * call enddef again, but this time no error is expected + */ + err = nc_close(ncid); CHECK_ERR + + if (nerrs) printf(".... failed with %d errors\n",nerrs); + else printf(".... pass\n"); + + return (nerrs > 0); +} diff --git a/nc_test4/tst_converts2.c b/nc_test4/tst_converts2.c index c5a2566b4..1e870e981 100644 --- a/nc_test4/tst_converts2.c +++ b/nc_test4/tst_converts2.c @@ -10,7 +10,7 @@ #include #include "err_macros.h" #include "netcdf.h" -#include "math.h" +#include #define FILE_NAME "tst_converts2.nc" #define VAR_NAME "Monkey" diff --git a/ncdump/tst_fileinfo.sh b/ncdump/tst_fileinfo.sh index afe907491..fb6c730b9 100755 --- a/ncdump/tst_fileinfo.sh +++ b/ncdump/tst_fileinfo.sh @@ -1,18 +1,19 @@ #!/bin/sh -if test "x$srcdir" = x ; then srcdir=`pwd`; fi +if test "x$srcdir" = x ; then srcdir=`pwd`; fi . ../test_common.sh set -e +set -x echo "" EXIT=0 -NCF=${srcdir}/ncdump/nc4_fileinfo.nc -HDF=${srcdir}/ncdump/hdf5_fileinfo.hdf -NF=${srcdir}/ncdump/ref_tst_compounds4.nc +NCF=${top_srcdir}/ncdump/nc4_fileinfo.nc +HDF=${top_srcdir}/ncdump/hdf5_fileinfo.hdf +NF=${top_srcdir}/ncdump/ref_tst_compounds4.nc -# Do a false negative test +# Do a false negative test rm -f ./tmp_tst_fileinfo if $NCDUMP -s $NF | fgrep '_IsNetcdf4 = 0' > ./tmp_tst_fileinfo ; then echo "Pass: False negative for file: $NF" @@ -42,4 +43,3 @@ rm -f $NCF rm -f $HDF exit $EXIT -