From eda449b9473728d5d0d9fc782abafb4e85500aba Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Wed, 16 Jan 2019 15:51:22 -0500 Subject: [PATCH 1/7] ncconfigure: add NC_UNUSED macro This should be used to indicate that a variable is unused in a codeblock. --- include/ncconfigure.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/ncconfigure.h b/include/ncconfigure.h index 42085dc88b..3495e37514 100644 --- a/include/ncconfigure.h +++ b/include/ncconfigure.h @@ -85,4 +85,8 @@ typedef unsigned short ushort; typedef unsigned int uint; #endif +#ifndef NC_UNUSED +#define NC_UNUSED(var) (void)var +#endif + #endif /* NCCONFIGURE_H */ From a747216c33d1e9744f6a13d2a9a8064f6529ad93 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 10:45:42 -0500 Subject: [PATCH 2/7] warnings: mark conditionally used parameters --- libdispatch/dparallel.c | 23 +++++++++++++++++++++++ libsrc/posixio.c | 6 ++++++ libsrc4/nc4var.c | 3 +++ 3 files changed, 32 insertions(+) diff --git a/libdispatch/dparallel.c b/libdispatch/dparallel.c index a62351435f..78a1adec82 100644 --- a/libdispatch/dparallel.c +++ b/libdispatch/dparallel.c @@ -98,6 +98,11 @@ int nc_create_par(const char *path, int cmode, MPI_Comm comm, MPI_Info info, int *ncidp) { #ifndef USE_PARALLEL + NC_UNUSED(path); + NC_UNUSED(cmode); + NC_UNUSED(comm); + NC_UNUSED(info); + NC_UNUSED(ncidp); return NC_ENOPAR; #else NC_MPI_INFO data; @@ -197,6 +202,11 @@ nc_open_par(const char *path, int omode, MPI_Comm comm, MPI_Info info, int *ncidp) { #ifndef USE_PARALLEL + NC_UNUSED(path); + NC_UNUSED(omode); + NC_UNUSED(comm); + NC_UNUSED(info); + NC_UNUSED(ncidp); return NC_ENOPAR; #else NC_MPI_INFO mpi_data; @@ -245,6 +255,11 @@ nc_open_par_fortran(const char *path, int omode, int comm, int info, int *ncidp) { #ifndef USE_PARALLEL + NC_UNUSED(path); + NC_UNUSED(omode); + NC_UNUSED(comm); + NC_UNUSED(info); + NC_UNUSED(ncidp); return NC_ENOPAR; #else MPI_Comm comm_c; @@ -344,6 +359,9 @@ int nc_var_par_access(int ncid, int varid, int par_access) { #ifndef USE_PARALLEL + NC_UNUSED(ncid); + NC_UNUSED(varid); + NC_UNUSED(par_access); return NC_ENOPAR; #else int stat = NC_NOERR; @@ -399,6 +417,11 @@ nc_create_par_fortran(const char *path, int cmode, int comm, int info, int *ncidp) { #ifndef USE_PARALLEL + NC_UNUSED(path); + NC_UNUSED(cmode); + NC_UNUSED(comm); + NC_UNUSED(info); + NC_UNUSED(ncidp); return NC_ENOPAR; #else MPI_Comm comm_c; diff --git a/libsrc/posixio.c b/libsrc/posixio.c index 328b13aaf6..71a91aff16 100644 --- a/libsrc/posixio.c +++ b/libsrc/posixio.c @@ -184,7 +184,11 @@ blksize(int fd) return 8192; } /* else, silent in the face of error */ +#else + NC_UNUSED(fd); #endif +#else + NC_UNUSED(fd); #endif return (size_t) 2 * pagesize(); } @@ -445,6 +449,7 @@ px_rel(ncio_px *const pxp, off_t offset, int rflags) && offset < pxp->bf_offset + (off_t) pxp->bf_extent); assert(pIf(fIsSet(rflags, RGN_MODIFIED), fIsSet(pxp->bf_rflags, RGN_WRITE))); + NC_UNUSED(offset); if(fIsSet(rflags, RGN_MODIFIED)) { @@ -1152,6 +1157,7 @@ ncio_spx_rel(ncio *const nciop, off_t offset, int rflags) assert(offset < pxp->bf_offset + X_ALIGN); assert(pxp->bf_cnt % X_ALIGN == 0 ); #endif + NC_UNUSED(offset); if(fIsSet(rflags, RGN_MODIFIED)) { diff --git a/libsrc4/nc4var.c b/libsrc4/nc4var.c index 7c9b55c538..a60c1a1846 100644 --- a/libsrc4/nc4var.c +++ b/libsrc4/nc4var.c @@ -390,6 +390,9 @@ int NC4_var_par_access(int ncid, int varid, int par_access) { #ifndef USE_PARALLEL4 + NC_UNUSED(ncid); + NC_UNUSED(varid); + NC_UNUSED(par_access); return NC_ENOPAR; #else NC *nc; From eb0b9b8bbd54e6989f3ea53e346258a8cd659ec5 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 10:46:05 -0500 Subject: [PATCH 3/7] ncuri: check the right preprocessor definition --- libdispatch/ncuri.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c index 03a7419654..26aa02a9d8 100644 --- a/libdispatch/ncuri.c +++ b/libdispatch/ncuri.c @@ -67,7 +67,7 @@ static char* queryallow = static char* userpwdallow = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!$&'()*+,-.;=_~?#/"; -#ifndef HAVE_STRNCMP +#ifndef HAVE_STRNDUP #define strndup ncstrndup /* Not all systems have strndup, so provide one*/ char* From b3f34432a352712e687e641a58652eba6abe6948 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 10:46:25 -0500 Subject: [PATCH 4/7] warnings: mark unused parameters --- libdispatch/nclog.c | 1 + libdispatch/nctime.c | 2 ++ libsrc/posixio.c | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/libdispatch/nclog.c b/libdispatch/nclog.c index 4e0adbfd83..1289772d22 100644 --- a/libdispatch/nclog.c +++ b/libdispatch/nclog.c @@ -212,6 +212,7 @@ Each line will be sent using nclog with the specified tag. void nclogtextn(int tag, const char* text, size_t count) { + NC_UNUSED(tag); if(!nclogging || nclogstream == NULL) return; fwrite(text,1,count,nclogstream); fflush(nclogstream); diff --git a/libdispatch/nctime.c b/libdispatch/nctime.c index aed5ac9842..909f3cfbe7 100644 --- a/libdispatch/nctime.c +++ b/libdispatch/nctime.c @@ -23,6 +23,7 @@ #include #include #include +#include "ncconfigure.h" #include "nctime.h" static int cuErrOpts; /* Error options */ @@ -659,6 +660,7 @@ Cdh2e(CdTime *htime, double *etime) static int cdValidateTime(cdCalenType timetype, cdCompTime comptime) { + NC_UNUSED(timetype); if(comptime.month<1 || comptime.month>12){ cdError("Error on time conversion: invalid month = %hd\n",comptime.month); return 1; diff --git a/libsrc/posixio.c b/libsrc/posixio.c index 71a91aff16..ed7993b222 100644 --- a/libsrc/posixio.c +++ b/libsrc/posixio.c @@ -802,6 +802,7 @@ px_double_buffer(ncio *const nciop, off_t to, off_t from, int status = NC_NOERR; void *src; void *dest; + NC_UNUSED(rflags); #if INSTRUMENT fprintf(stderr, "\tdouble_buffr %ld %ld %ld\n", @@ -1406,6 +1407,7 @@ ncio_spx_move(ncio *const nciop, off_t to, off_t from, static int ncio_spx_sync(ncio *const nciop) { + NC_UNUSED(nciop); /* NOOP */ return NC_NOERR; } @@ -1598,6 +1600,7 @@ posixio_create(const char *path, int ioflags, int oflags = (O_RDWR|O_CREAT); int fd; int status; + NC_UNUSED(parameters); if(initialsz < (size_t)igeto + igetsz) initialsz = (size_t)igeto + igetsz; @@ -1742,6 +1745,7 @@ posixio_open(const char *path, int oflags = fIsSet(ioflags, NC_WRITE) ? O_RDWR : O_RDONLY; int fd = -1; int status = 0; + NC_UNUSED(parameters); if(path == NULL || *path == 0) return EINVAL; From 94a0259f0e205b78887c2f72f4669243da18e625 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 10:47:03 -0500 Subject: [PATCH 5/7] NC_mktmp: pass the remaining space to strncat This could overflow if `tmp` only had a few bytes left in its space given its current contents. --- libdispatch/dutil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/dutil.c b/libdispatch/dutil.c index f79575ef3b..843d90550f 100644 --- a/libdispatch/dutil.c +++ b/libdispatch/dutil.c @@ -208,7 +208,7 @@ NC_mktmp(const char* base) char spid[7]; if(rno < 0) rno = -rno; snprintf(spid,sizeof(spid),"%06d",rno); - strncat(tmp,spid,sizeof(tmp)); + strncat(tmp,spid,sizeof(tmp) - strlen(tmp) - 1); } #endif /* HAVE_MKTEMP */ #ifdef _MSC_VER From 8c331222ecbdfeb399d41f78f303ffe6de51e9cb Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 13:41:09 -0500 Subject: [PATCH 6/7] warnings: store sizes in size_t --- libdispatch/drc.c | 4 ++-- libdispatch/ncuri.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libdispatch/drc.c b/libdispatch/drc.c index 2ad784472d..318b42ec95 100644 --- a/libdispatch/drc.c +++ b/libdispatch/drc.c @@ -396,8 +396,8 @@ rcsearch(const char* prefix, const char* rcname, char** pathp) { char* path = NULL; FILE* f = NULL; - int plen = strlen(prefix); - int rclen = strlen(rcname); + size_t plen = strlen(prefix); + size_t rclen = strlen(rcname); int ret = NC_NOERR; size_t pathlen = plen+rclen+1; /*+1 for '/' */ diff --git a/libdispatch/ncuri.c b/libdispatch/ncuri.c index 26aa02a9d8..a023cf6738 100644 --- a/libdispatch/ncuri.c +++ b/libdispatch/ncuri.c @@ -258,7 +258,7 @@ ncuriparse(const char* uri0, NCURI** durip) isfile = (strcmp(tmp.protocol,"file")==0); if(isfile) { - int l = strlen(p); /* to test if we have enough characters */ + size_t l = strlen(p); /* to test if we have enough characters */ hashost = 0; /* always */ if(l >= 2 && p[1] == ':' && strchr(DRIVELETTERS,p[0]) != NULL) { /* case 1 */ ; /* p points to the start of the path */ From 82d72dfa47e6eaca929c6abfb67f2736765a0b27 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Fri, 11 Jan 2019 13:41:19 -0500 Subject: [PATCH 7/7] nctime: expand basetime's size It ends up being `basetime_1 + basetime_2` with a space in between. Make enough room to ensure that it is not truncated. --- libdispatch/nctime.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdispatch/nctime.c b/libdispatch/nctime.c index 909f3cfbe7..08df27bb15 100644 --- a/libdispatch/nctime.c +++ b/libdispatch/nctime.c @@ -310,7 +310,7 @@ cdParseRelunits(cdCalenType timetype, char* relunits, cdUnitTime* unit, cdCompTi char charunits[CD_MAX_RELUNITS]; char basetime_1[CD_MAX_CHARTIME]; char basetime_2[CD_MAX_CHARTIME]; - char basetime[CD_MAX_CHARTIME]; + char basetime[2 * CD_MAX_CHARTIME + 1]; int nconv1, nconv2, nconv; /* Parse the relunits */