diff --git a/.travis.yml b/.travis.yml index 5a51ff050..2a0845022 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,3 @@ -# blocklist -branches: - except: - - /.*[.]dmh/ - sudo: required language: c services: diff --git a/CMakeLists.txt b/CMakeLists.txt index c1b89a43d..b0c554fdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1002,7 +1002,6 @@ IF(ENABLE_PARALLEL4 AND ENABLE_NETCDF_4) ENDIF() ENDIF() - # Options to enable parallel IO, tests. SET(STATUS_PNETCDF "OFF") OPTION(ENABLE_PNETCDF "Build with parallel I/O for classic and 64-bit offset files using parallel-netcdf." OFF) @@ -1108,6 +1107,12 @@ IF(ENABLE_PARALLEL_TESTS AND USE_PARALLEL) ENDIF() ENDIF() +# Enable special filter test; experimental when using cmake. +OPTION(ENABLE_FILTER_TEST "Enable special filter test. Ignored if netCDF4 is not enabled" OFF) +IF(USE_NETCDF4) + SET(ENABLE_FILTER_TEST OFF CACHE BOOL "") +ENDIF() + # Determine whether or not to generate documentation. OPTION(ENABLE_DOXYGEN "Enable generation of doxygen-based documentation." OFF) IF(ENABLE_DOXYGEN) @@ -1248,6 +1253,7 @@ CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE("sys/wait.h" HAVE_SYS_WAIT_H) CHECK_INCLUDE_FILE("sys/mman.h" HAVE_SYS_MMAN_H) CHECK_INCLUDE_FILE("sys/resource.h" HAVE_SYS_RESOURCE_H) +CHECK_INCLUDE_FILE("sys/cdefs.h" HAVE_SYS_CDEFS_H) CHECK_INCLUDE_FILE("fcntl.h" HAVE_FCNTL_H) CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) CHECK_INCLUDE_FILE("pstdint.h" HAVE_PSTDINT_H) diff --git a/cf b/cf index b348ff4e2..d1da1ee20 100644 --- a/cf +++ b/cf @@ -6,9 +6,9 @@ FAST=1 HDF5=1 DAP=1 -SZIP=1 +#SZIP=1 #HDF4=1 -PNETCDF=1 +#PNETCDF=1 #PAR4=1 if test $# != 0 ; then @@ -117,7 +117,7 @@ FLAGS="$FLAGS --enable-logging" #FLAGS="$FLAGS --disable-properties-attribute" #FLAGS="$FLAGS --disable-silent-rules" #FLAGS="$FLAGS --with-testservers=remotestserver.localhost:8083" -FLAGS="$FLAGS --enable-filter-test" +#FLAGS="$FLAGS --enable-filter-test" if test "x$PAR4" != x1 ; then FLAGS="$FLAGS --disable-parallel4" diff --git a/cf.cmake b/cf.cmake index 095af5879..919a2e94e 100644 --- a/cf.cmake +++ b/cf.cmake @@ -1,8 +1,17 @@ # Visual Studio -VS=1 -if test "x$1" = xsetup ; then -VSSETUP=1 +case "$1" in +vs|VS) VS=1 ;; +linux|nix) unset VS ;; +*) echo "Must specify env: vs|linux"; exit 1; ;; +esac + +if test "x$VS" = x1 ; then + if test "x$2" = xsetup ; then + VSSETUP=1 + else + unset VSSETUP + fi fi #export NCPATHDEBUG=1 diff --git a/config.h.cmake.in b/config.h.cmake.in index c06912525..80c07b73d 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -410,6 +410,9 @@ are set when opening a binary file on Windows. */ /* Define to 1 if you have the `sysconf' function. */ #cmakedefine HAVE_SYSCONF 1 +/* Define to 1 if you have the header file. */ +#cmakedefine HAVE_SYS_CDEFS_H 1 + /* Define to 1 if you have the header file, and it defines `DIR'. */ #cmakedefine HAVE_SYS_DIR_H 1 diff --git a/configure.ac b/configure.ac index aa7b5fa83..12a221ef6 100644 --- a/configure.ac +++ b/configure.ac @@ -795,6 +795,8 @@ AC_FUNC_VPRINTF AC_CHECK_HEADERS([sys/resource.h]) #fi +AC_CHECK_HEADERS([sys/cdefs.h]) + # Check for that conforms to C99 requirements AC_HEADER_STDBOOL diff --git a/dap4_test/Makefile.am b/dap4_test/Makefile.am index 05dd4bbdb..cca89e4df 100644 --- a/dap4_test/Makefile.am +++ b/dap4_test/Makefile.am @@ -58,6 +58,8 @@ EXTRA_DIST = test_parse.sh test_meta.sh test_data.sh \ baseline baselineraw baselineremote CMakeLists.txt CLEANFILES = *.exe +# This should only be left behind if using parallel io +CLEANFILES += tmp_* # One last thing BUILT_SOURCES = .daprc diff --git a/dap4_test/test_data.c b/dap4_test/test_data.c index 10df5fa32..5b4569e95 100644 --- a/dap4_test/test_data.c +++ b/dap4_test/test_data.c @@ -47,6 +47,8 @@ main(int argc, char** argv) if((ret=nc_close(ncid))) goto done; done: +#ifdef DEBUG fprintf(stderr,"code=%d %s\n",ret,nc_strerror(ret)); +#endif return (ret ? 1 : 0); } diff --git a/include/ncconfigure.h b/include/ncconfigure.h index d1ef846f2..0b20bb5f9 100644 --- a/include/ncconfigure.h +++ b/include/ncconfigure.h @@ -10,6 +10,10 @@ #ifndef NCCONFIGURE_H #define NCCONFIGURE_H 1 +#ifdef HAVE_STDLIB_H +#include +#endif + /* This is included in bottom of config.h. It is where, @@ -42,6 +46,14 @@ char *nulldup(const char* s); #endif #endif +#ifndef HAVE_STRLCAT +#ifdef _MSC_VER +/* Windows strlcat_s is equivalent to strlcat, but different arg order */ +#define strlcat(d,s,n) strcat_s((d),(n),(s)) +#else +extern size_t strlcat(char* dst, const char* src, size_t dsize); +#endif +#endif #ifndef nulldup #define nulldup(s) ((s)==NULL?NULL:strdup(s)) diff --git a/libdap2/dapattr.c b/libdap2/dapattr.c index 4bd39c28f..f491cf9ca 100644 --- a/libdap2/dapattr.c +++ b/libdap2/dapattr.c @@ -151,368 +151,3 @@ buildattribute(char* name, nc_type ptype, return THROW(ncstat); } -#if 0 -/* -Given a das attribute walk it to see if it -has at least 1 actual attribute (no recursion) -*/ -static int -hasattribute(OClink conn, OCdasnode dasnode) -{ - int i; - OCerror ocstat = OC_NOERR; - int tf = 0; /* assume false */ - OCtype ocsubtype; - NClist* subnodes = nclistnew(); - - OCCHECK(oc_dds_octype(conn,dasnode,&ocsubtype)); - if(ocsubtype == OC_Attribute) return 1; /* this is an attribute */ - ASSERT((ocsubtype == OC_Attributeset)); - - OCCHECK(collect_subnodes(conn,dasnode,subnodes)); - for(i=0;ioc.conn; - size_t nsubnodes; - NClist* dasglobals = nclistnew(); - NClist* dasnodes = nclistnew(); - NClist* dodsextra = nclistnew(); - NClist* varnodes = nclistnew(); - NClist* alldasnodes = nclistnew(); - - if(ddsroot == NULL || dasroot == NULL) return NC_NOERR; - - ocstat = collect_alldasnodes(conn,dasroot,alldasnodes); - - /* 1. collect all the relevant DAS nodes; - namely those that contain at least one - attribute value. - Simultaneously look for potential ambiguities - if found; complain but continue: result are indeterminate. - also collect globals and DODS_EXTRA separately. - */ - for(i=0;ifullname :: DDS->fullname - 2. DAS->name :: DDS->fullname (support DAS names with embedded '.' - 3. DAS->name :: DDS->name - 4. special case for DODS. Apply 1-3 on DODS parent. - */ - for(i=0;iocname)==0) { - mergedas1(nccomm,conn,dds,das); - /* remove from dasnodes list*/ - nclistset(dasnodes,i,(void*)NULL); - } - nullfree(ddsfullname); - } - nullfree(ocfullname); - nullfree(ocbasename); - } - - /* 4. Assign globals */ - for(i=0;iattributes == NULL) dds->attributes = nclistnew(); - /* assign the simple attributes in the das set to this dds node*/ - OCCHECK(oc_inq_nsubnodes(conn,das,&nsubnodes)); - OCCHECK(oc_inq_subnodes(conn,das,&subnodes)); - for(i=0;iattributes,(void*)att); - } else if(octype == OC_Attributeset - && (strcmp(ocname,"DODS")==0 - || strcmp(ocname,"DODS_EXTRA")==0)) { - /* Turn the DODS special attributes into into - special attributes for dds node */ - OCCHECK(oc_inq_nsubnodes(conn,attnode,&ndodsnodes)); - OCCHECK(oc_inq_subnodes(conn,attnode,&dodsnodes)); - for(j=0;jinvisible = 1; - nclistpush(dds->attributes,(void*)att); - - /* Define extra semantics associated with DODS and DODS_EXTRA attribute */ - if(strcmp(dodsname,"strlen")==0) { - unsigned int maxstrlen = 0; - if(nclistlength(stringvalues) > 0) { - char* stringval = (char*)nclistget(stringvalues,0); - if(0==sscanf(stringval,"%u",&maxstrlen)) maxstrlen = 0; - } - dds->dodsspecial.maxstrlen = maxstrlen; -#ifdef DEBUG -fprintf(stderr,"%s.maxstrlen=%d\n",dds->ocname,(int)dds->dodsspecial.maxstrlen); -#endif - } else if(strcmp(dodsname,"dimName")==0) { - if(nclistlength(stringvalues) > 0) { - char* stringval = (char*)nclistget(stringvalues,0); - dds->dodsspecial.dimname = nulldup(stringval); -#ifdef DEBUG -fprintf(stderr,"%s.dimname=%s\n",dds->ocname,dds->dodsspecial.dimname); -#endif - } else dds->dodsspecial.dimname = NULL; - } else if(strcmp(dodsname,"Unlimited_Dimension")==0) { - char* stringval = NULL; - if(nclistlength(stringvalues) > 0) - stringval = (char*)nclistget(stringvalues,0); - if(stringval != NULL) { - if(nccomm->cdf.recorddimname != NULL) { - if(strcmp(stringval,nccomm->cdf.recorddimname) != 0) - nclog(NCLOGWARN,"Duplicate DODS_EXTRA:Unlimited_Dimension specifications"); - } else { - nccomm->cdf.recorddimname = nulldup(stringval); -#ifdef DEBUG -fprintf(stderr,"%s.Unlimited_Dimension=%s\n",dds->ocname,nccomm->cdf.recorddimname); -#endif - } - } - } /* else ignore */ - nullfree(dodsname); - } - nullfree(dodsnodes); - } - nullfree(ocname); - } - -done: - nullfree(subnodes); - if(ocstat != OC_NOERR) ncstat = ocerrtoncerr(ocstat); - return THROW(ncstat); -} - -static int -isglobalname(char* name) -{ - int len = strlen(name); - int glen = strlen("global"); - char* p; - if(len < glen) return 0; - p = name + (len - glen); - if(strcasecmp(p,"global") != 0) - return 0; - return 1; -} - - -static OCerror -collect_alldasnodes(OClink link, OCddsnode dasnode, NClist* alldasnodes) -{ - size_t nsubnodes,i; - OCerror ocstat = OC_NOERR; - nclistpush(alldasnodes,(void*)dasnode); - ocstat = oc_dds_nsubnodes(link,dasnode,&nsubnodes); - if(ocstat != OC_NOERR) goto done; - for(i=0;istride, (unsigned long)slice->last); } - strcat(buf,tmp); + strlcat(buf,tmp,sizeof(buf)); return strdup(tmp); } diff --git a/libdap2/dapodom.c b/libdap2/dapodom.c index 8df5756c9..965f335e2 100644 --- a/libdap2/dapodom.c +++ b/libdap2/dapodom.c @@ -79,14 +79,14 @@ dapodom_print(Dapodometer* odom) char tmp[64]; line[0] = '\0'; if(odom->rank == 0) { - strcat(line,"[]"); + strlcat(line,"[]",sizeof(line)); } else for(i=0;irank;i++) { sprintf(tmp,"[%lu/%lu:%lu:%lu]", (size_t)odom->index[i], (size_t)odom->start[i], (size_t)odom->stride[i], (size_t)odom->length[i]); - strcat(line,tmp); + strlcat(line,tmp,sizeof(line)); } return line; } diff --git a/libdap2/daputil.c b/libdap2/daputil.c index 120a3109c..47d184c0c 100644 --- a/libdap2/daputil.c +++ b/libdap2/daputil.c @@ -442,13 +442,13 @@ simplepathstring(NClist* names, char* separator) len += strlen(name); len += strlen(separator); } - len++; /* null terminator */ - result = (char*)malloc(len); + len++; /* room for strlcat to null terminate */ + result = (char*)malloc(len+1); result[0] = '\0'; for(i=0;i 0) strcat(result,separator); - strcat(result,segment); + if(i > 0) strlcat(result,separator,len); + strlcat(result,segment,len); } return result; } @@ -776,10 +776,13 @@ repairname(const char* name, const char* badchars) const char *p; char *q; int c; + int nnlen = 0; if(name == NULL) return NULL; - newname = (char*)malloc(1+(3*strlen(name))); /* max needed */ - newname[0] = '\0'; /* so we can use strcat */ + nnlen = (3*strlen(name)); /* max needed */ + nnlen++; /* room for strlcat to add nul */ + newname = (char*)malloc(1+nnlen); /* max needed */ + newname[0] = '\0'; /* so we can use strlcat */ for(p=name,q=newname;(c=*p);p++) { if(strchr(badchars,c) != NULL) { int digit; @@ -790,11 +793,11 @@ repairname(const char* name, const char* badchars) digit = (c & 0x0f); newchar[2] = hexdigits[digit]; newchar[3] = '\0'; - strcat(newname,newchar); + strlcat(newname,newchar,nnlen); q += 3; /*strlen(newchar)*/ } else *q++ = c; - *q = '\0'; /* so we can always do strcat */ + *q = '\0'; /* so we can always do strlcat */ } *q = '\0'; /* ensure trailing null */ return newname; diff --git a/libdap2/ncd2dispatch.c b/libdap2/ncd2dispatch.c index 37f424bbf..9e30e7bd2 100644 --- a/libdap2/ncd2dispatch.c +++ b/libdap2/ncd2dispatch.c @@ -316,10 +316,14 @@ NCD2_open(const char* path, int mode, #endif #ifdef OCCOMPILEBYDEFAULT + { int rullen = 0; /* set the compile flag by default */ - dapcomm->oc.rawurltext = (char*)emalloc(strlen(path)+strlen("[compile]")+1); - strcpy(dapcomm->oc.rawurltext,"[compile]"); - strcat(dapcomm->oc.rawurltext, path); + rullen = strlen(path)+strlen("[compile]");; + rullen++; /* strlcat nul */ + dapcomm->oc.rawurltext = (char*)emalloc(rullen+1); + strncpy(dapcomm->oc.rawurltext,"[compile]",rullen); + strlcat(dapcomm->oc.rawurltext, path, rullen); + } #else dapcomm->oc.rawurltext = strdup(path); #endif @@ -905,15 +909,14 @@ buildattribute(NCDAPCOMMON* dapcomm, NCattribute* att, nc_type vartype, int vari char* s = (char*)nclistget(att->values,i); newlen += (1+strlen(s)); } - if(newlen > 0) - newstring = (char*)malloc(newlen); - - MEMCHECK(newstring,NC_ENOMEM); + newlen++; /* for strlcat nul */ + newstring = (char*)malloc(newlen+1); + MEMCHECK(newstring,NC_ENOMEM); newstring[0] = '\0'; for(i=0;ivalues,i); - if(i > 0) strcat(newstring,"\n"); - strcat(newstring,s); + if(i > 0) strlcat(newstring,"\n",newlen); + strlcat(newstring,s,newlen); } dapexpandescapes(newstring); if(newstring[0]=='\0') @@ -1137,11 +1140,14 @@ fprintf(stderr,"conflict: %s[%lu] %s[%lu]\n", nullfree(dim->ncbasename); if(dim->dim.index1 > 0) {/* need to fix conflicting names (see above) */ char sindex[64]; + size_t baselen; snprintf(sindex,sizeof(sindex),"_%d",dim->dim.index1); - dim->ncbasename = (char*)malloc(strlen(sindex)+strlen(legalname)+1); + baselen = strlen(sindex)+strlen(legalname); + baselen++; /* for strlcat nul */ + dim->ncbasename = (char*)malloc(baselen+1); if(dim->ncbasename == NULL) {nullfree(legalname); return NC_ENOMEM;} - strcpy(dim->ncbasename,legalname); - strcat(dim->ncbasename,sindex); + strncpy(dim->ncbasename,legalname,baselen); + strlcat(dim->ncbasename,sindex,baselen); nullfree(legalname); } else {/* standard case */ dim->ncbasename = legalname; @@ -1271,9 +1277,9 @@ applyclientparams(NCDAPCOMMON* nccomm) CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->varnodes,i); /* Define the client param stringlength for this variable*/ var->maxstringlength = 0; /* => use global dfalt */ - strcpy(tmpname,"stringlength_"); + strncpy(tmpname,"stringlength_",sizeof(tmpname)); pathstr = makeocpathstring(conn,var->ocnode,"."); - strncat(tmpname,pathstr,NC_MAX_NAME); + strlcat(tmpname,pathstr,sizeof(tmpname)); nullfree(pathstr); value = paramlookup(nccomm,tmpname); if(value != NULL && strlen(value) != 0) { @@ -1285,13 +1291,13 @@ applyclientparams(NCDAPCOMMON* nccomm) CDFnode* var = (CDFnode*)nclistget(nccomm->cdf.ddsroot->tree->nodes,i); if(var->nctype != NC_Sequence) continue; var->sequencelimit = dfaltseqlim; - strcpy(tmpname,"nolimit_"); + strncpy(tmpname,"nolimit_",sizeof(tmpname)); pathstr = makeocpathstring(conn,var->ocnode,"."); - strncat(tmpname,pathstr,NC_MAX_NAME); + strlcat(tmpname,pathstr,sizeof(tmpname)); if(paramlookup(nccomm,tmpname) != NULL) var->sequencelimit = 0; - strcpy(tmpname,"limit_"); - strncat(tmpname,pathstr,NC_MAX_NAME); + strncpy(tmpname,"limit_",sizeof(tmpname)); + strlcat(tmpname,pathstr,sizeof(tmpname)); value = paramlookup(nccomm,tmpname); if(value != NULL && strlen(value) != 0) { if(sscanf(value,"%d",&len) && len > 0) diff --git a/libdap2/test_vara.c b/libdap2/test_vara.c index c4bd0e0b3..c15cdbf65 100644 --- a/libdap2/test_vara.c +++ b/libdap2/test_vara.c @@ -90,8 +90,8 @@ main() exit(1); } printf("Using test server: %s\n",svc); - strcpy(URL,svc); - strcat(URL,DTSTEST); + strncpy(URL,svc,sizeof(URL)); + strlcat(URL,DTSTEST,sizeof(URL)); memset((void*)target,0,sizeof(target)); diff --git a/libdap4/d4file.c b/libdap4/d4file.c index ccd481744..f8089937c 100644 --- a/libdap4/d4file.c +++ b/libdap4/d4file.c @@ -349,10 +349,12 @@ set_curl_properties(NCD4INFO* d4info) int ret = NC_NOERR; if(d4info->auth.curlflags.useragent == NULL) { - size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION) + 1; - char* agent = (char*)malloc(len+1); + char* agent; + size_t len = strlen(DFALTUSERAGENT) + strlen(VERSION); + len++; /*strlcat nul*/ + agent = (char*)malloc(len+1); strncpy(agent,DFALTUSERAGENT,len); - strncat(agent,VERSION,len); + strlcat(agent,VERSION,len); d4info->auth.curlflags.useragent = agent; } diff --git a/libdap4/d4odom.c b/libdap4/d4odom.c index 497550589..419bb41f5 100644 --- a/libdap4/d4odom.c +++ b/libdap4/d4odom.c @@ -76,14 +76,14 @@ d4odom_print(D4odometer* odom) char tmp[64]; line[0] = '\0'; if(odom->rank == 0) { - strcat(line,"[]"); + strlcat(line,"[]",sizeof(line)); } else for(i=0;irank;i++) { sprintf(tmp,"[%lu/%lu:%lu:%lu]", (size_t)odom->index[i], (size_t)odom->start[i], (size_t)odom->stride[i], (size_t)odom->length[i]); - strcat(line,tmp); + strlcat(line,tmp,sizeof(line)); } return line; } diff --git a/libdap4/d4parser.c b/libdap4/d4parser.c index dc5656824..d7fd29c09 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)); - strncat(name,"_t",sizeof(name)-strlen(name)); + strlcat(name,"_t",sizeof(name)); 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)); - strncat(name,"_base",sizeof(name)-strlen(name)); + strlcat(name,"_base",sizeof(name)); 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)); - strncat(name,"_t",sizeof(name)-strlen(name)); + strlcat(name,"_t",sizeof(name)); SETNAME(vlentype,name); vlentype->basetype = structtype; /* Set the basetype */ diff --git a/libdap4/d4util.c b/libdap4/d4util.c index 91992ac8d..ab4f40eb3 100644 --- a/libdap4/d4util.c +++ b/libdap4/d4util.c @@ -112,19 +112,20 @@ NCD4_makeFQN(NCD4node* node) nclistinsert(path,0,g); } estimate = (estimate*2) + 2*nclistlength(path); - /* start at 1 to avoid dataset */ + estimate++; /*strlcat nul*/ fqn = (char*)malloc(estimate+1); if(fqn == NULL) goto done; fqn[0] = '\0'; /* Create the group-based fqn prefix */ + /* start at 1 to avoid dataset */ for(i=1;isort != NCD4_GROUP) break; /* Add in the group name */ char* escaped = backslashEscape(elem->name); if(escaped == NULL) {free(fqn); fqn = NULL; goto done;} - strcat(fqn,"/"); - strcat(fqn,escaped); + strlcat(fqn,"/",estimate); + strlcat(fqn,escaped,estimate); free(escaped); } /* Add in the final name part (if not group) */ @@ -132,8 +133,8 @@ NCD4_makeFQN(NCD4node* node) int last = nclistlength(path)-1; NCD4node* n = (NCD4node*)nclistget(path,last); char* name = NCD4_makeName(n,"."); - strcat(fqn,"/"); - strcat(fqn,name); + strlcat(fqn,"/",estimate); + strlcat(fqn,name,estimate); nullfree(name); } @@ -160,7 +161,7 @@ NCD4_makeName(NCD4node* elem, const char* sep) nclistinsert(path,0,n); estimate += (1+(2*strlen(n->name))); } - + estimate++; /*strlcat nul*/ fqn = (char*)malloc(estimate+1); if(fqn == NULL) goto done; fqn[0] = '\0'; @@ -170,8 +171,8 @@ NCD4_makeName(NCD4node* elem, const char* sep) char* escaped = backslashEscape(elem->name); if(escaped == NULL) {free(fqn); fqn = NULL; goto done;} if(i > 0) - strcat(fqn,sep); - strcat(fqn,escaped); + strlcat(fqn,sep,estimate); + strlcat(fqn,escaped,estimate); free(escaped); } done: diff --git a/libdispatch/dfile.c b/libdispatch/dfile.c index 732e8ffc9..1a4e8eba3 100644 --- a/libdispatch/dfile.c +++ b/libdispatch/dfile.c @@ -27,7 +27,7 @@ Research/Unidata. See COPYRIGHT file for more info. /* If Defined, then use only stdio for all magic number io; otherwise use stdio or mpio as required. */ -#define USE_STDIO +#undef DEBUG /** Sort info for open/read/close of @@ -48,7 +48,9 @@ struct MagicFile { static int openmagic(struct MagicFile* file); static int readmagic(struct MagicFile* file, long pos, char* magic); static int closemagic(struct MagicFile* file); +#ifdef DEBUG static void printmagic(const char* tag, char* magic,struct MagicFile*); +#endif extern int NC_initialized; extern int NC_finalized; @@ -171,11 +173,7 @@ NC_check_file_type(const char *path, int flags, void *parameters, int diskless = ((flags & NC_DISKLESS) == NC_DISKLESS); #ifdef USE_PARALLEL -#ifdef USE_STDIO - int use_parallel = 0; -#else int use_parallel = ((flags & NC_MPIIO) == NC_MPIIO); -#endif #endif /* USE_PARALLEL */ int inmemory = (diskless && ((flags & NC_INMEMORY) == NC_INMEMORY)); struct MagicFile file; @@ -2062,7 +2060,6 @@ openmagic(struct MagicFile* file) /* Get its length */ NC_MEM_INFO* meminfo = (NC_MEM_INFO*)file->parameters; file->filelen = (long long)meminfo->size; -fprintf(stderr,"XXX: openmagic: memory=0x%llx size=%ld\n",(long long unsigned int)meminfo->memory,meminfo->size); goto done; } #ifdef USE_PARALLEL @@ -2128,13 +2125,13 @@ readmagic(struct MagicFile* file, long pos, char* magic) if(file->inmemory) { char* mempos; NC_MEM_INFO* meminfo = (NC_MEM_INFO*)file->parameters; -fprintf(stderr,"XXX: readmagic: memory=0x%llx size=%ld\n",(long long unsigned int)meminfo->memory,meminfo->size); -fprintf(stderr,"XXX: readmagic: pos=%ld filelen=%lld\n",pos,file->filelen); if((pos + MAGIC_NUMBER_LEN) > meminfo->size) {status = NC_EDISKLESS; goto done;} mempos = ((char*)meminfo->memory) + pos; memcpy((void*)magic,mempos,MAGIC_NUMBER_LEN); -printmagic("XXX: readmagic",magic,file); +#ifdef DEBUG + printmagic("XXX: readmagic",magic,file); +#endif goto done; } #ifdef USE_PARALLEL @@ -2191,6 +2188,7 @@ done: return status; } +#ifdef DEBUG static void printmagic(const char* tag, char* magic, struct MagicFile* f) { @@ -2211,3 +2209,4 @@ printmagic(const char* tag, char* magic, struct MagicFile* f) fprintf(stderr,"\n"); fflush(stderr); } +#endif diff --git a/libdispatch/dstring.c b/libdispatch/dstring.c index 3466e5395..2a3cece0d 100644 --- a/libdispatch/dstring.c +++ b/libdispatch/dstring.c @@ -5,8 +5,8 @@ /* $Id: string.c,v 1.76 2010/05/26 21:43:33 dmh Exp $ */ #include "config.h" -#include #include +#include #include #include #include @@ -14,7 +14,6 @@ #include "rnd.h" #include "ncutf8.h" - /* There are 3 levels of UTF8 checking: 1=> (exact)validating 2=>relaxed and 3=>very relaxed */ @@ -302,3 +301,58 @@ strdup(const char* s) #endif /**************************************************/ +/* strlcat */ +/* + * Copyright (c) 1998, 2015 Todd C. Miller + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef HAVE_STRLCAT +#ifndef _MSC_VER /* We will use strcat_s */ +/* + * Appends src to string dst of size dsize (unlike strncat, dsize is the + * full size of dst, not space left). At most dsize-1 characters + * will be copied. Always NUL terminates (unless dsize <= strlen(dst)). + * Returns strlen(src) + MIN(dsize, strlen(initial dst)). + * If retval >= dsize, truncation occurred. + */ +size_t +strlcat(char* dst, const char* src, size_t dsize) +{ + const char *odst = dst; + const char *osrc = src; + size_t n = dsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end. */ + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - odst; + n = dsize - dlen; + + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; + n--; + } + src++; + } + *dst = '\0'; + + return(dlen + (src - osrc)); /* count does not include NUL */ +} +#endif /*!_MSC_VER*/ +#endif /*!HAVE_STRLCAT*/ diff --git a/libdispatch/dutil.c b/libdispatch/dutil.c index 897989357..bb612c94c 100644 --- a/libdispatch/dutil.c +++ b/libdispatch/dutil.c @@ -246,7 +246,7 @@ NC_mktmp(const char* base) #endif /* !HAVE_MKSTEMP */ if(fd < 0) { nclog(NCLOGERR, "Could not create temp file: %s",tmp); - return (NC_EPERM); + return NULL; } else close(fd); return strdup(tmp); diff --git a/ncdap_test/Makefile.am b/ncdap_test/Makefile.am index dad689349..1ab1738dc 100644 --- a/ncdap_test/Makefile.am +++ b/ncdap_test/Makefile.am @@ -85,6 +85,8 @@ EXTRA_DIST = tst_ncdap3.sh \ t_ncf330.c tst_ber.sh CLEANFILES = test_varm3 test_cvt3 results/*.dmp results/*.das results/*.dds datadds* t_dap3a test_nstride_cached *.exe +# This should only be left behind if using parallel io +CLEANFILES += tmp_* # This rule are used if someone wants to rebuild t_dap3a.c # Otherwise never invoked, but records how to do it. diff --git a/ncdap_test/t_dap.c b/ncdap_test/t_dap.c index ba3bdacb9..a73bb6b5a 100644 --- a/ncdap_test/t_dap.c +++ b/ncdap_test/t_dap.c @@ -110,7 +110,7 @@ int main() { int ncid, varid; int ncstat = NC_NOERR; - char* url; + char url[8192]; const char* topsrcdir; size_t len; #ifndef USE_NETCDF4 @@ -123,20 +123,15 @@ int main() topsrcdir = gettopsrcdir(); - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); url[0] = '\0'; #ifdef DEBUG - strcat(url,"[log][show=fetch]"); + strlcat(url,"[log][show=fetch]",sizeof(url)); #endif - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); + strlcat(url,"file://",sizeof(url)); + strlcat(url,topsrcdir,sizeof(url)); + strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url)); printf("*** Test: var conversions on URL: %s\n",url); diff --git a/ncdap_test/t_dap3a.c b/ncdap_test/t_dap3a.c index 1ee374487..518358f49 100644 --- a/ncdap_test/t_dap3a.c +++ b/ncdap_test/t_dap3a.c @@ -111,7 +111,7 @@ int main() { int ncid, varid; int ncstat = NC_NOERR; - char* url; + char url[8102]; const char* topsrcdir; size_t len; #ifndef USE_NETCDF4 @@ -124,20 +124,15 @@ int main() topsrcdir = gettopsrcdir(); - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); url[0] = '\0'; #ifdef DEBUG - strcat(url,"[log][show=fetch]"); + strlcat(url,"[log][show=fetch]",sizeof(url)); #endif - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); + strlcat(url,"file://",sizeof(url)); + strlcat(url,topsrcdir,sizeof(url)); + strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url)); printf("*** Test: var conversions on URL: %s\n",url); diff --git a/ncdap_test/t_dap3c.c b/ncdap_test/t_dap3c.c index 3ce713e41..313437b87 100644 --- a/ncdap_test/t_dap3c.c +++ b/ncdap_test/t_dap3c.c @@ -27,9 +27,9 @@ main() topsrcdir = gettopsrcdir(); - strcpy(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); + strncpy(url,"file://",sizeof(url)); + strlcat(url,topsrcdir,sizeof(url)); + strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url)); if ((retval = nc_open(url, 0, &ncid))) ERR(retval); diff --git a/ncdap_test/t_dap4.c b/ncdap_test/t_dap4.c deleted file mode 100644 index 8144d2ece..000000000 --- a/ncdap_test/t_dap4.c +++ /dev/null @@ -1,466 +0,0 @@ -#include -#include -#include -#include -#include "netcdf.h" -#include "t_srcdir.h" - -#undef GENERATE - -#undef DEBUG - -/* Test (some) internal/external type conversions - using following DAP dataset (test.02). - Dataset { - Byte b[DIMSIZE]; - Int32 i32[DIMSIZE]; - UInt32 ui32[DIMSIZE]; - Int16 i16[DIMSIZE]; - UInt16 ui16[DIMSIZE]; - Float32 f32[DIMSIZE]; - Float64 f64[DIMSIZE]; - String s[DIMSIZE]; - Url u[DIMSIZE]; - } OneDimensionalSimpleArrays; -*/ - -#define NDIMS 1 -#define DIMSIZE 25 -#define STRLEN 64 - -#ifndef USE_NETCDF4 -#define NC_UBYTE 7 /* unsigned 1 byte int */ -#define NC_USHORT 8 /* unsigned 2-byte int */ -#define NC_UINT 9 /* unsigned 4-byte int */ -#define NC_INT64 10 /* signed 8-byte int */ -#define NC_UINT64 11 /* unsigned 8-byte int */ -#define NC_STRING 12 /* string */ -#endif - - -#define CHECK(expr) check(expr,__FILE__,__LINE__); - -#define COMMA (i==0?"":",") - -#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__) - -static int failure = 0; - -static void compare(nc_type,nc_type,void*,void*,char*,char*,int); - -static void -report(const int i, const char* var, const int line) -{ - fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line); - failure = 1; -} - -static void -check(int ncstat, char* file, int line) -{ - if(ncstat == NC_NOERR) return; - fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n", - ncstat,nc_strerror(ncstat),file,line); - exit(1); -} - -/* return 1 if |f1-f2| > 0.05 */ -static int -fdiff(double f1, double f2) -{ - double delta = (f1 - f2); - if(delta < 0) delta = - delta; - if(delta > 0.05) { - fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta); - } - return (delta > 0.05?1:0); -} - -static char ch_data[DIMSIZE]; -static signed char int8_data[DIMSIZE]; -static unsigned char uint8_data[DIMSIZE]; -static int int8toint32_data[DIMSIZE]; -static float int82float32_data[DIMSIZE]; -static short int16_data[DIMSIZE]; -static int int16toint32_data[DIMSIZE]; -static float int162float32_data[DIMSIZE]; -static int int32_data[DIMSIZE]; -static float int32tofloat32_data[DIMSIZE]; -static long int32toilong_data[DIMSIZE]; -static float float32_data[DIMSIZE]; -static double float64_data[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3_data[DIMSIZE][STRLEN]; -#endif - -static char ch[DIMSIZE]; -static signed char int8[DIMSIZE]; -static unsigned char uint8[DIMSIZE]; -static short int16[DIMSIZE]; -static int int32[DIMSIZE]; -static float float32[DIMSIZE]; -static double float64[DIMSIZE]; -static long ilong[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3[DIMSIZE][STRLEN]; -#endif - -int main() -{ - int ncid, varid; - int ncstat = NC_NOERR; - char* url; - const char* topsrcdir; - size_t len; -#ifndef USE_NETCDF4 - int i,j; -#endif - - /* location of our target url: use file:// to avoid remote - server downtime issues - */ - - topsrcdir = gettopsrcdir(); - - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); - url[0] = '\0'; - -#ifdef DEBUG - strcat(url,"[log][show=fetch]"); -#endif - - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); - - printf("*** Test: var conversions on URL: %s\n",url); - - /* open file, get varid */ - CHECK(nc_open(url, NC_NOWRITE, &ncid)); - - /* extract the string case for netcdf-3*/ -#ifndef USE_NETCDF4 - CHECK(nc_inq_varid(ncid, "s", &varid)); - CHECK(nc_get_var_text(ncid,varid,(char*)string3)); -#ifdef GENERATE - printf("static %s string3_data[DIMSIZE][STRLEN]={","char"); - for(i=0;i 0 - && string3[i][j] != '\n' - && string3[i][j] != '\r' - && string3[i][j] != '\t' - &&(string3[i][j] < ' ' || string3[i][j] >= '\177')) - string3[i][j] = '?'; - } - printf("%s\"%s\"",COMMA,string3[i]); - } - printf("};\n"); -#else - fprintf(stdout,"*** testing: %s\n","string3"); - for(i=0;i -#include -#include -#include -#include "netcdf.h" -#include "t_srcdir.h" - -#undef GENERATE - -#undef DEBUG - -/* Test (some) internal/external type conversions - using following DAP dataset (test.02). - Dataset { - Byte b[DIMSIZE]; - Int32 i32[DIMSIZE]; - UInt32 ui32[DIMSIZE]; - Int16 i16[DIMSIZE]; - UInt16 ui16[DIMSIZE]; - Float32 f32[DIMSIZE]; - Float64 f64[DIMSIZE]; - String s[DIMSIZE]; - Url u[DIMSIZE]; - } OneDimensionalSimpleArrays; -*/ - -#define NDIMS 1 -#define DIMSIZE 25 -#define STRLEN 64 - -#ifndef USE_NETCDF4 -#define NC_UBYTE 7 /* unsigned 1 byte int */ -#define NC_USHORT 8 /* unsigned 2-byte int */ -#define NC_UINT 9 /* unsigned 4-byte int */ -#define NC_INT64 10 /* signed 8-byte int */ -#define NC_UINT64 11 /* unsigned 8-byte int */ -#define NC_STRING 12 /* string */ -#endif - - -#define CHECK(expr) check(expr,__FILE__,__LINE__); - -#define COMMA (i==0?"":",") - -#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__) - -static int failure = 0; - -static void compare(nc_type,nc_type,void*,void*,char*,char*,int); - -static void -report(const int i, const char* var, const int line) -{ - fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line); - failure = 1; -} - -static void -check(int ncstat, char* file, int line) -{ - if(ncstat == NC_NOERR) return; - fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n", - ncstat,nc_strerror(ncstat),file,line); - exit(1); -} - -/* return 1 if |f1-f2| > 0.05 */ -static int -fdiff(double f1, double f2) -{ - double delta = (f1 - f2); - if(delta < 0) delta = - delta; - if(delta > 0.05) { - fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta); - } - return (delta > 0.05?1:0); -} - -static char ch_data[DIMSIZE]; -static signed char int8_data[DIMSIZE]; -static unsigned char uint8_data[DIMSIZE]; -static int int8toint32_data[DIMSIZE]; -static float int82float32_data[DIMSIZE]; -static short int16_data[DIMSIZE]; -static int int16toint32_data[DIMSIZE]; -static float int162float32_data[DIMSIZE]; -static int int32_data[DIMSIZE]; -static float int32tofloat32_data[DIMSIZE]; -static long int32toilong_data[DIMSIZE]; -static float float32_data[DIMSIZE]; -static double float64_data[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3_data[DIMSIZE][STRLEN]; -#endif - -static char ch[DIMSIZE]; -static signed char int8[DIMSIZE]; -static unsigned char uint8[DIMSIZE]; -static short int16[DIMSIZE]; -static int int32[DIMSIZE]; -static float float32[DIMSIZE]; -static double float64[DIMSIZE]; -static long ilong[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3[DIMSIZE][STRLEN]; -#endif - -int main() -{ - int ncid, varid; - int ncstat = NC_NOERR; - char* url; - const char* topsrcdir; - size_t len; -#ifndef USE_NETCDF4 - int i,j; -#endif - - /* location of our target url: use file:// to avoid remote - server downtime issues - */ - - /* Assume that TESTS_ENVIRONMENT was set */ - topsrcdir = gettopsrcdir(); - - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); - url[0] = '\0'; - -#ifdef DEBUG - strcat(url,"[log][show=fetch]"); -#endif - - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); - - printf("*** Test: var conversions on URL: %s\n",url); - - /* open file, get varid */ - CHECK(nc_open(url, NC_NOWRITE, &ncid)); - - /* extract the string case for netcdf-3*/ -#ifndef USE_NETCDF4 - CHECK(nc_inq_varid(ncid, "s", &varid)); - CHECK(nc_get_var_text(ncid,varid,(char*)string3)); -#ifdef GENERATE - printf("static %s string3_data[DIMSIZE][STRLEN]={","char"); - for(i=0;i 0 - && string3[i][j] != '\n' - && string3[i][j] != '\r' - && string3[i][j] != '\t' - &&(string3[i][j] < ' ' || string3[i][j] >= '\177')) - string3[i][j] = '?'; - } - printf("%s\"%s\"",COMMA,string3[i]); - } - printf("};\n"); -#else - fprintf(stdout,"*** testing: %s\n","string3"); - for(i=0;i -#include -#include -#include -#include "netcdf.h" - - -#undef GENERATE - -#undef DEBUG - -/* Test (some) internal/external type conversions - using following DAP dataset (test.02). - Dataset { - Byte b[DIMSIZE]; - Int32 i32[DIMSIZE]; - UInt32 ui32[DIMSIZE]; - Int16 i16[DIMSIZE]; - UInt16 ui16[DIMSIZE]; - Float32 f32[DIMSIZE]; - Float64 f64[DIMSIZE]; - String s[DIMSIZE]; - Url u[DIMSIZE]; - } OneDimensionalSimpleArrays; -*/ - -#define NDIMS 1 -#define DIMSIZE 25 -#define STRLEN 64 - -#ifndef USE_NETCDF4 -#define NC_UBYTE 7 /* unsigned 1 byte int */ -#define NC_USHORT 8 /* unsigned 2-byte int */ -#define NC_UINT 9 /* unsigned 4-byte int */ -#define NC_INT64 10 /* signed 8-byte int */ -#define NC_UINT64 11 /* unsigned 8-byte int */ -#define NC_STRING 12 /* string */ -#endif - - -#define CHECK(expr) check(expr,__FILE__,__LINE__); - -#define COMMA (i==0?"":",") - -#define COMPARE(t1,t2,v1,v2) compare(t1,t2,(void*)v1,(void*)v2,#v2,__FILE__,__LINE__) - -static int failure = 0; - -static void compare(nc_type,nc_type,void*,void*,char*,char*,int); - -static void -report(const int i, const char* var, const int line) -{ - fprintf(stdout,"%s mismatch: [%d] file: %s line: %d\n",var,i,__FILE__,line); - failure = 1; -} - -static void -check(int ncstat, char* file, int line) -{ - if(ncstat == NC_NOERR) return; - fprintf(stderr,"*** FAIL: %d (%s) at %s:%d\n", - ncstat,nc_strerror(ncstat),file,line); - exit(1); -} - -/* return 1 if |f1-f2| > 0.05 */ -static int -fdiff(double f1, double f2) -{ - double delta = (f1 - f2); - if(delta < 0) delta = - delta; - if(delta > 0.05) { - fprintf(stdout,"fdiff: %1.3f %1.3f delta=%1.3f\n",f1,f2,delta); - } - return (delta > 0.05?1:0); -} - -static char ch_data[DIMSIZE]; -static signed char int8_data[DIMSIZE]; -static unsigned char uint8_data[DIMSIZE]; -static int int8toint32_data[DIMSIZE]; -static float int82float32_data[DIMSIZE]; -static short int16_data[DIMSIZE]; -static int int16toint32_data[DIMSIZE]; -static float int162float32_data[DIMSIZE]; -static int int32_data[DIMSIZE]; -static float int32tofloat32_data[DIMSIZE]; -static long int32toilong_data[DIMSIZE]; -static float float32_data[DIMSIZE]; -static double float64_data[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3_data[DIMSIZE][STRLEN]; -#endif - -static char ch[DIMSIZE]; -static signed char int8v[DIMSIZE]; -static unsigned char uint8v[DIMSIZE]; -static short int16v[DIMSIZE]; -static int int32v[DIMSIZE]; -static float float32v[DIMSIZE]; -static double float64v[DIMSIZE]; -static long ilong[DIMSIZE]; -#ifndef USE_NETCDF4 -static char string3[DIMSIZE][STRLEN]; -#endif - -int main() -{ - int ncid, varid; - int ncstat = NC_NOERR; - char* url; - char* topsrcdir; - size_t len; -#ifndef USE_NETCDF4 - int i,j; -#endif - - /* location of our target url: use file:// to avoid remote - server downtime issues - */ - - /* Assume that TESTS_ENVIRONMENT was set */ - topsrcdir = getenv("TOPSRCDIR"); - if(topsrcdir == NULL) { - fprintf(stderr,"*** FAIL: $abs_top_srcdir not defined: location= %s:%d\n",__FILE__,__LINE__); - exit(1); - } - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); - url[0] = '\0'; - -#ifdef DEBUG - strcat(url,"[log][show=fetch]"); -#endif - - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); - - printf("*** Test: var conversions on URL: %s\n",url); - - /* open file, get varid */ - CHECK(nc_open(url, NC_NOWRITE, &ncid)); - - /* extract the string case for netcdf-3*/ -#ifndef USE_NETCDF4 - CHECK(nc_inq_varid(ncid, "s", &varid)); - CHECK(nc_get_var_text(ncid,varid,(char*)string3)); -#ifdef GENERATE - printf("static %s string3_data[DIMSIZE][STRLEN]={","char"); - for(i=0;i 0 - && string3[i][j] != '\n' - && string3[i][j] != '\r' - && string3[i][j] != '\t' - &&(string3[i][j] < ' ' || string3[i][j] >= '\177')) - string3[i][j] = '?'; - } - printf("%s\"%s\"",COMMA,string3[i]); - } - printf("};\n"); -#else - fprintf(stdout,"*** testing: %s\n","string3"); - for(i=0;i -#include -#include -#include "netcdf.h" -#include "t_srcdir.h" - -#define VAR "i32" - -#define ERRCODE 2 -#define ERR(e) {printf("Error: %s\n", nc_strerror(e)); exit(ERRCODE);} - -#undef DEBUG - -int -main() -{ - int ncid, varid; - int retval; - int i32[100]; - size_t start[1]; - size_t count[1]; - int ok = 1; - - const char* topsrcdir; - char url[4096]; - - topsrcdir = gettopsrcdir(); - - strcpy(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); - - if ((retval = nc_open(url, 0, &ncid))) - ERR(retval); - if ((retval = nc_inq_varid(ncid, VAR, &varid))) - ERR(retval); - - start[0] = 0; - count[0] = 26; - if ((retval = nc_get_vara_int(ncid, varid, start, count, i32))) - if(retval != NC_EINVALCOORDS) { - printf("nc_get_vara_int did not return NC_EINVALCOORDS"); - ok = 0; - } - - nc_close(ncid); - - printf(ok?"*** PASS\n":"*** FAIL\n"); - return 0; -} diff --git a/ncdap_test/test_cvt.c b/ncdap_test/test_cvt.c index 2e9500a0e..bf7a2a43a 100644 --- a/ncdap_test/test_cvt.c +++ b/ncdap_test/test_cvt.c @@ -110,7 +110,7 @@ int main() { int ncid, varid; int ncstat = NC_NOERR; - char* url; + char url[8192]; const char* topsrcdir; size_t len; #ifndef USE_NETCDF4 @@ -123,20 +123,15 @@ int main() topsrcdir = gettopsrcdir(); - len = strlen("file://") + strlen(topsrcdir) + strlen("/ncdap_test/testdata3/test.02") + 1; -#ifdef DEBUG - len += strlen("[log][show=fetch]"); -#endif - url = (char*)malloc(len); url[0] = '\0'; #ifdef DEBUG - strcat(url,"[log][show=fetch]"); + strlcat(url,"[log][show=fetch]",sizeof(url)); #endif - strcat(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.02"); + strlcat(url,"file://",sizeof(url)); + strlcat(url,topsrcdir,sizeof(url)); + strlcat(url,"/ncdap_test/testdata3/test.02",sizeof(url)); printf("*** Test: var conversions on URL: %s\n",url); diff --git a/ncdap_test/test_nstride_cached.c b/ncdap_test/test_nstride_cached.c index 47fe01f08..72c63760e 100644 --- a/ncdap_test/test_nstride_cached.c +++ b/ncdap_test/test_nstride_cached.c @@ -101,7 +101,6 @@ main() exit(0); } - strcpy(url,URL); snprintf(url,sizeof(url),URL,svc); for (idim=0; idim<5; idim++) { diff --git a/ncdap_test/test_partvar.c b/ncdap_test/test_partvar.c index 7ccb4bdd6..c2af1d8e8 100644 --- a/ncdap_test/test_partvar.c +++ b/ncdap_test/test_partvar.c @@ -106,9 +106,9 @@ main() fprintf(stderr,"Cannot locate test server\n"); exit(0); } - strcpy(url,PARAMS); - strcat(url,svc); - strcat(url,DTSTEST); + strncpy(url,PARAMS,sizeof(url)); + strlcat(url,svc,sizeof(url)); + strlcat(url,DTSTEST,sizeof(url)); printf("test_partvar: url=%s\n",url); diff --git a/ncdap_test/test_partvar2.c b/ncdap_test/test_partvar2.c index 4ddfccb77..3d2251808 100644 --- a/ncdap_test/test_partvar2.c +++ b/ncdap_test/test_partvar2.c @@ -95,9 +95,9 @@ main() fprintf(stderr,"Cannot locate test server\n"); exit(1); } - strcpy(url,PARAMS); - strcat(url,svc); - strcat(url,DTSTEST); + strncpy(url,PARAMS,sizeo(url)); + strlcat(url,svc,sizeof(url)); + strlcat(url,DTSTEST,sizeof(url)); printf("test_partvar: url=%s\n",url); diff --git a/ncdap_test/test_vara.c b/ncdap_test/test_vara.c index e3ae045b5..b819a29c5 100644 --- a/ncdap_test/test_vara.c +++ b/ncdap_test/test_vara.c @@ -1,3 +1,4 @@ +#include "config.h" #include #include #include @@ -81,9 +82,9 @@ main() topsrcdir = gettopsrcdir(); - strcpy(url,"file://"); - strcat(url,topsrcdir); - strcat(url,"/ncdap_test/testdata3/test.06"); + strncpy(url,"file://",sizeof(url)); + strlcat(url,topsrcdir,sizeof(url)); + strlcat(url,"/ncdap_test/testdata3/test.06",sizeof(url)); printf("test_vara: url=%s\n",url); diff --git a/ncdap_test/test_varm3.c b/ncdap_test/test_varm3.c index 30c5782dd..37e0ee6c3 100644 --- a/ncdap_test/test_varm3.c +++ b/ncdap_test/test_varm3.c @@ -99,8 +99,8 @@ main() fprintf(stderr,"Cannot locate test server\n"); exit(0); } - strcpy(url,svc); - strcat(url,TESTPATH); + strncpy(url,svc,sizeof(url)); + strlcat(url,TESTPATH,sizeof(url)); printf("*** Test: varm on URL: %s\n",url); diff --git a/ncdump/dumplib.c b/ncdump/dumplib.c index 45434d6f1..863ad7a71 100644 --- a/ncdump/dumplib.c +++ b/ncdump/dumplib.c @@ -113,62 +113,6 @@ char float_att_fmt[] = "%#.NNgf"; char float_attx_fmt[] = "%#.NNg"; char double_att_fmt[] = "%#.NNg"; -#ifndef HAVE_STRLCAT -/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} -#endif /* ! HAVE_STRLCAT */ - - /* magic number stored in a safebuf and checked, hoping it will be * changed if buffer was overwritten inadvertently */ #define SAFEBUF_CERT 2147114711 diff --git a/ncdump/dumplib.h b/ncdump/dumplib.h index be6e72034..2ce26ea06 100644 --- a/ncdump/dumplib.h +++ b/ncdump/dumplib.h @@ -50,11 +50,6 @@ extern char double_att_fmt[]; extern "C" { #endif -#ifndef HAVE_STRLCAT -/* Append src to dst of size siz */ -extern size_t strlcat(char *dst, const char *src, size_t siz); -#endif /* ! HAVE_STRLCAT */ - /* In case different formats specified with -d option, set them here. */ extern void set_formats ( int flt_digs, int dbl_digs ); diff --git a/ncgen3/genlib.c b/ncgen3/genlib.c index 177e45c60..a54c06646 100644 --- a/ncgen3/genlib.c +++ b/ncgen3/genlib.c @@ -1837,61 +1837,6 @@ grow_aarray( *arpp = (struct atts *) erealloc(*arpp, 2 * nar * sizeof(struct atts)); } -#ifndef HAVE_STRLCAT -/* $OpenBSD: strlcat.c,v 1.12 2005/03/30 20:13:52 otto Exp $ */ - -/* - * Copyright (c) 1998 Todd C. Miller - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - -/* - * Appends src to string dst of size siz (unlike strncat, siz is the - * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz <= strlen(dst)). - * Returns strlen(src) + MIN(siz, strlen(initial dst)). - * If retval >= siz, truncation occurred. - */ -size_t -strlcat(char *dst, const char *src, size_t siz) -{ - char *d = dst; - const char *s = src; - size_t n = siz; - size_t dlen; - - /* Find the end of dst and adjust bytes left but don't go past end */ - while (n-- != 0 && *d != '\0') - d++; - dlen = d - dst; - n = siz - dlen; - - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; - - return(dlen + (s - src)); /* count does not include NUL */ -} -#endif /* ! HAVE_STRLCAT */ - /* * Replace special chars in name so it can be used in C and Fortran diff --git a/ncgen3/genlib.h b/ncgen3/genlib.h index 6c6f38a64..45f139a68 100644 --- a/ncgen3/genlib.h +++ b/ncgen3/genlib.h @@ -80,11 +80,6 @@ extern void nc_fill ( nc_type type, size_t num, void* datp, /* reset symbol table to empty, defined in ncgen.y */ extern void clearout(void); -/* In case we are missing strlcat */ -#ifndef HAVE_STRLCAT -extern size_t strlcat(char *dst, const char *src, size_t siz); -#endif - #ifdef __cplusplus } #endif diff --git a/ncgen3/load.c b/ncgen3/load.c index c02c4b412..401dd3d2b 100644 --- a/ncgen3/load.c +++ b/ncgen3/load.c @@ -15,10 +15,6 @@ #include "ncgen.h" #include "genlib.h" -#ifndef HAVE_STRLCAT -extern size_t strlcat(char *dst, const char *src, size_t siz); -#endif - extern int netcdf_flag; extern int c_flag; extern int fortran_flag; diff --git a/oc2/occurlfunctions.c b/oc2/occurlfunctions.c index a24b6b914..53cc0274c 100644 --- a/oc2/occurlfunctions.c +++ b/oc2/occurlfunctions.c @@ -28,8 +28,8 @@ check(OCstate* state, int flag, void* value) } else { char show[65]; char* s = (char*)value; - strncpy(show,s,64); - show[64] = '\0'; + strncpy(show,s,sizeof(show)-1); + show[sizeof(show)-1] = '\0'; OCDBG2("%s=%s",name,show); } #endif diff --git a/oc2/ocdump.c b/oc2/ocdump.c index 205b01532..839eb9362 100644 --- a/oc2/ocdump.c +++ b/oc2/ocdump.c @@ -232,14 +232,14 @@ ocdumpclause(OCprojectionclause* ref) static void -addfield(char* field, char* line, int align) +addfield(char* field, size_t llen, char* line, int align) { int len,rem; - strcat(line,"|"); - strcat(line,field); + strlcat(line,"|",llen); + strlcat(line,field,llen); len = strlen(field); rem = (align - len); - while(rem-- > 0) strcat(line," "); + while(rem-- > 0) strlcat(line," ",llen); } static void @@ -264,27 +264,27 @@ dumpfield(size_t index, char* n8, int isxdr) /* offset */ sprintf(tmp,"%6zd",index); - addfield(tmp,line,5); + addfield(tmp,sizeof(line),line,5); memcpy(form.cv,n8,4); /* straight hex*/ sprintf(tmp,"%08x",form.uv); - addfield(tmp,line,8); + addfield(tmp,sizeof(line),line,8); if(isxdr) {swapinline32(&form.uv);} /* unsigned integer */ sprintf(tmp,"%12u",form.uv); - addfield(tmp,line,12); + addfield(tmp,sizeof(line),line,12); /* signed integer */ sprintf(tmp,"%12d",form.sv); - addfield(tmp,line,12); + addfield(tmp,sizeof(line),line,12); /* float */ sprintf(tmp,"%#g",form.fv); - addfield(tmp,line,12); + addfield(tmp,sizeof(line),line,12); /* char[4] */ { @@ -303,13 +303,13 @@ dumpfield(size_t index, char* n8, int isxdr) } } - addfield(tmp,line,16); + addfield(tmp,sizeof(line),line,16); /* double */ memcpy(dform.cv,n8,(size_t)(2*XDRUNIT)); if(isxdr) xxdrntohdouble(dform.cv,&dform.d); sprintf(tmp,"%#g",dform.d); - addfield(tmp,line,12); + addfield(tmp,sizeof(line),line,12); fprintf(stdout,"%s\n",line); } @@ -326,14 +326,14 @@ typedmemorydump(char* memory, size_t len, int fromxdr) /* build the header*/ line[0] = '\0'; - addfield("offset",line,6); - addfield("hex",line,8); - addfield("uint",line,12); - addfield("int",line,12); - addfield("float",line,12); - addfield("char[4]",line,16); - addfield("double",line,12); - strcat(line,"\n"); + addfield("offset",sizeof(line),line,6); + addfield("hex",sizeof(line),line,8); + addfield("uint",sizeof(line),line,12); + addfield("int",sizeof(line),line,12); + addfield("float",sizeof(line),line,12); + addfield("char[4]",sizeof(line),line,16); + addfield("double",sizeof(line),line,12); + strlcat(line,"\n",sizeof(line)); fprintf(stdout,"%s",line); count = (len / sizeof(int)); @@ -367,9 +367,9 @@ simplememorydump(char* memory, size_t len, int fromxdr) /* build the header*/ line[0] = '\0'; - addfield("offset",line,6); - addfield("XDR (hex)",line,9); - addfield("!XDR (hex)",line,10); + addfield("offset",sizeof(line),line,6); + addfield("XDR (hex)",sizeof(line),line,9); + addfield("!XDR (hex)",sizeof(line),line,10); fprintf(stdout,"%s\n",line); count = (len / sizeof(int)); @@ -384,11 +384,11 @@ simplememorydump(char* memory, size_t len, int fromxdr) if(!xxdr_network_order) swapinline32(&v); line[0] = '\0'; sprintf(tmp,"%6d",i); - addfield(tmp,line,6); + addfield(tmp,sizeof(line),line,6); sprintf(tmp,"%08x",vx); - addfield(tmp,line,9); + addfield(tmp,sizeof(line),line,9); sprintf(tmp,"%08x",v); - addfield(tmp,line,10); + addfield(tmp,sizeof(line),line,10); fprintf(stdout,"%s\n",line); } fflush(stdout); diff --git a/oc2/ocnode.c b/oc2/ocnode.c index e4f0e8f52..20805e295 100644 --- a/oc2/ocnode.c +++ b/oc2/ocnode.c @@ -399,13 +399,13 @@ mergedods1(OCnode* dds, OCnode* dods) */ size_t len = strlen(attnode->name) + strlen(dods->name) - + strlen(".") - + 1; /*null*/ - char* newname = (char*)malloc(len); + + strlen("."); + len++; /*strlcat nul*/ + char* newname = (char*)malloc(len+1); if(newname == NULL) return OC_ENOMEM; - strcpy(newname,dods->name); - strcat(newname,"."); - strcat(newname,attnode->name); + strncpy(newname,dods->name,len); + strlcat(newname,".",len); + strlcat(newname,attnode->name,len); att = makeattribute(newname,attnode->etype,attnode->att.values); free(newname); nclistpush(dds->attributes,(void*)att);