From 6c249365f067b7d9b3b0613fae1cee8bc4edfd62 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 30 Nov 2023 17:16:05 +0000 Subject: [PATCH 01/16] Change `bbAppendn` argument type to `size_t` Fixes lots of warnings about conversions changing value --- ncgen/bytebuffer.c | 4 ++-- ncgen/bytebuffer.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ncgen/bytebuffer.c b/ncgen/bytebuffer.c index e0446a6c39..e06c3b4912 100644 --- a/ncgen/bytebuffer.c +++ b/ncgen/bytebuffer.c @@ -144,9 +144,9 @@ bbCatbuf(Bytebuffer* bb, const Bytebuffer* s) } int -bbAppendn(Bytebuffer* bb, const void* elem, const unsigned int n0) +bbAppendn(Bytebuffer* bb, const void* elem, const size_t n0) { - unsigned int n = n0; + size_t n = n0; if(bb == NULL || elem == NULL) return bbFail(); if(n == 0) {n = strlen((char*)elem);} while(!bbNeed(bb,(n+1))) {if(!bbSetalloc(bb,0)) return bbFail();} diff --git a/ncgen/bytebuffer.h b/ncgen/bytebuffer.h index 6ecbc5b5e7..10777c8a9c 100644 --- a/ncgen/bytebuffer.h +++ b/ncgen/bytebuffer.h @@ -1,6 +1,7 @@ /* Copyright 2018, UCAR/Unidata and OPeNDAP, Inc. See the COPYRIGHT file for more information. */ +#include #ifndef BYTEBUFFER_H #define BYTEBUFFER_H 1 @@ -33,7 +34,7 @@ EXTERNC int bbGet(Bytebuffer*,unsigned int); EXTERNC int bbSet(Bytebuffer*,unsigned int,char); EXTERNC int bbAppend(Bytebuffer*,const char); /* Add at Tail */ -EXTERNC int bbAppendn(Bytebuffer*,const void*,unsigned int); /* Add at Tail */ +EXTERNC int bbAppendn(Bytebuffer*, const void*, size_t); /* Add at Tail */ /* Insert 1 or more characters at given location */ EXTERNC int bbInsert(Bytebuffer*,const unsigned int,const char); From c80d71213dab500abbcc3a1d09c1f8aeb16a18a5 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 30 Nov 2023 17:16:54 +0000 Subject: [PATCH 02/16] Fix a bunch of sign conversion warnings from `ncgen.y` --- ncgen3/init.c | 3 ++- ncgen3/ncgen.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/ncgen3/init.c b/ncgen3/init.c index 068fd0eb77..bc7aab75f5 100644 --- a/ncgen3/init.c +++ b/ncgen3/init.c @@ -4,6 +4,7 @@ * $Header: /upc/share/CVS/netcdf-3/ncgen3/init.c,v 1.6 1997/05/23 11:41:14 russ Exp $ *********************************************************************/ +#include #include #include #include "generic.h" @@ -23,7 +24,7 @@ int natts; /* number of attributes */ int nvdims; /* number of dimensions for variables */ int dimnum; /* dimension number index for variables */ int varnum; /* variable number index for attributes */ -int valnum; /* value number index for attributes */ +size_t valnum; /* value number index for attributes */ int rec_dim; /* number of the unlimited dimension, if any */ size_t var_len; /* variable length (product of dimensions) */ size_t rec_len; /* number of elements for a record of data */ diff --git a/ncgen3/ncgen.h b/ncgen3/ncgen.h index a51b1d79a2..d5a157cec0 100644 --- a/ncgen3/ncgen.h +++ b/ncgen3/ncgen.h @@ -6,6 +6,7 @@ * $Header: /upc/share/CVS/netcdf-3/ncgen3/ncgen.h,v 1.8 1997/07/07 18:27:04 russ Exp $ *********************************************************************/ +#include #define MAX_NC_ATTSIZE 20000 /* max size of attribute (for ncgen) */ #define MAXTRST 5000 /* max size of string value (for ncgen) */ @@ -23,7 +24,7 @@ extern int natts; /* number of attributes */ extern int nvdims; /* number of dimensions for variables */ extern int dimnum; /* dimension number index for variables */ extern int varnum; /* variable number index for attributes */ -extern int valnum; /* number of values specified for variable */ +extern size_t valnum; /* number of values specified for variable */ extern int rec_dim; /* number of the unlimited dimension, if any */ extern size_t rec_len; /* number of elements for a record of data */ extern size_t var_len; /* variable length (product of dimensions) */ From 83faffacaa0fd4f26326b09167e91683434cd936 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 30 Nov 2023 17:18:34 +0000 Subject: [PATCH 03/16] Change type of string length member Fixes lots of sign-conversion warnings --- ncgen/data.h | 5 +++-- ncgen/genchar.c | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/ncgen/data.h b/ncgen/data.h index f822ff66fc..8342a2d7b1 100644 --- a/ncgen/data.h +++ b/ncgen/data.h @@ -3,6 +3,7 @@ * See netcdf/COPYRIGHT file for copying and redistribution conditions. *********************************************************************/ +#include #ifndef DATA_H #define DATA_H 1 @@ -36,8 +37,8 @@ typedef union Constvalue { float floatv; /* NC_FLOAT*/ double doublev; /* NC_DOUBLE*/ struct Stringv { /* NC_STRING*/ - int len; - char* stringv; + size_t len; + char* stringv; } stringv; struct Opaquev { /* NC_OPAQUE*/ int len; /* length as originally written (rounded to even number)*/ diff --git a/ncgen/genchar.c b/ncgen/genchar.c index 25ff0622fb..8526989eb9 100644 --- a/ncgen/genchar.c +++ b/ncgen/genchar.c @@ -4,6 +4,7 @@ *********************************************************************/ #include "includes.h" +#include /******************************************************/ /* Code for generating char variables etc; mostly @@ -14,7 +15,7 @@ static size_t gen_charconstant(NCConstant*, Bytebuffer*, int fillchar); static int getfillchar(Datalist* fillsrc); static void gen_leafchararray(Dimset*,int,Datalist*,Bytebuffer*, int); -static NCConstant* makeconst(int lineno, int len, char* str); +static NCConstant* makeconst(int lineno, size_t len, char* str); static void rebuildsingletons(Datalist* data); /* @@ -237,7 +238,7 @@ gen_charconstant(NCConstant* con, Bytebuffer* databuf, int fillchar) /* Create a new string constant */ static NCConstant* -makeconst(int lineno, int len, char* str) +makeconst(int lineno, size_t len, char* str) { NCConstant* con = nullconst(); con->nctype = NC_STRING; @@ -245,8 +246,8 @@ makeconst(int lineno, int len, char* str) con->filled = 0; con->value.stringv.len = len; /* We cannot use strdup because str might have embedded nuls */ - con->value.stringv.stringv = (char*)ecalloc((size_t)len+1); - memcpy((void*)con->value.stringv.stringv,(void*)str, (size_t)len); + con->value.stringv.stringv = (char*)ecalloc(len+1); + memcpy((void*)con->value.stringv.stringv,(void*)str, len); con->value.stringv.stringv[len] = '\0'; return con; } From 57e754f5795a653d15863b5878bd04acead2425b Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 30 Nov 2023 17:29:43 +0000 Subject: [PATCH 04/16] Silence lots conversion warnings in ncgen --- ncgen/bindata.c | 2 +- ncgen/bytebuffer.c | 3 ++- ncgen/cvt.c | 6 +++--- ncgen/data.c | 14 +++++++------- ncgen/genbin.c | 10 +++++----- ncgen/genc.c | 15 ++++++++------- ncgen/genchar.c | 2 +- ncgen/semantics.c | 2 +- ncgen/util.c | 10 ++++------ 9 files changed, 32 insertions(+), 32 deletions(-) diff --git a/ncgen/bindata.c b/ncgen/bindata.c index 1482176d03..5469ff2e21 100644 --- a/ncgen/bindata.c +++ b/ncgen/bindata.c @@ -105,7 +105,7 @@ bin_listbegin(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, { if(uidp) *uidp = ++bin_uid; if(lc == LISTCOMPOUND) - *((int*)liststate) = bbLength(buf); + *((int*)liststate) = (int)bbLength(buf); return 1; } diff --git a/ncgen/bytebuffer.c b/ncgen/bytebuffer.c index e06c3b4912..63bc50267d 100644 --- a/ncgen/bytebuffer.c +++ b/ncgen/bytebuffer.c @@ -2,6 +2,7 @@ See the COPYRIGHT file for more information. */ #include "config.h" +#include #include #include #include @@ -22,7 +23,7 @@ int bbdebug = 1; /* For debugging purposes*/ -static long +static int bbFail(void) { fflush(stdout); diff --git a/ncgen/cvt.c b/ncgen/cvt.c index dfd033087e..b7daa7483b 100644 --- a/ncgen/cvt.c +++ b/ncgen/cvt.c @@ -9,6 +9,7 @@ #include "bytebuffer.h" #include "isnan.h" #include +#include #ifndef nulldup @@ -71,7 +72,7 @@ case CASE(NC_CHAR,NC_CHAR): tmp.charv = src->value.charv; break; case CASE(NC_CHAR,NC_BYTE): - tmp.int8v = (unsigned char)src->value.charv; + tmp.int8v = (signed char)src->value.charv; break; case CASE(NC_CHAR,NC_UBYTE): tmp.uint8v = (unsigned char)src->value.charv; @@ -636,10 +637,9 @@ convertstringtochars(NCConstant* str) { int i; Datalist* dl; - int slen; char* s; - slen = str->value.stringv.len; + size_t slen = str->value.stringv.len; dl = builddatalist(slen); s = str->value.stringv.stringv; for(i=0;i /* for isprint() */ +#include #include "netcdf_aux.h" #include "netcdf_filter.h" @@ -32,12 +33,12 @@ void genbin_netcdf(void) { int stat, ncid; - int idim, ivar, iatt; + size_t idim, ivar, iatt; int ndims, nvars, natts, ngatts; const char* filename = rootgroup->file.filename; #ifdef USE_NETCDF4 - int ntyps, ngrps, igrp; + int ntyps, ngrps; #endif ndims = listlength(dimdefs); @@ -75,7 +76,7 @@ genbin_netcdf(void) #ifdef USE_NETCDF4 /* Define the group structure */ /* walking grdefs list will do a preorder walk of all defined groups*/ - for(igrp=0;igrpcontainer->nc_id,gsym->name,&gsym->nc_id); @@ -86,8 +87,7 @@ genbin_netcdf(void) #ifdef USE_NETCDF4 /* Define the types*/ if (ntyps > 0) { - int ityp; - for(ityp = 0; ityp < ntyps; ityp++) { + for(size_t ityp = 0; ityp < ntyps; ityp++) { Symbol* tsym = (Symbol*)listget(typdefs,ityp); genbin_deftype(tsym); } diff --git a/ncgen/genc.c b/ncgen/genc.c index 51b74abfcd..65aec192ab 100644 --- a/ncgen/genc.c +++ b/ncgen/genc.c @@ -6,6 +6,7 @@ #include "includes.h" #include /* for isprint() */ +#include #ifdef ENABLE_C @@ -37,13 +38,15 @@ static void genc_writeattr(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*); void genc_netcdf(void) { - int idim, ivar, iatt, maxdims; + size_t idim, ivar, iatt; + int maxdims; int ndims, nvars, natts, ngatts; char* cmode_string; const char *filename = rootgroup->file.filename; #ifdef USE_NETCDF4 - int igrp,ityp, ngrps, ntyps; + size_t igrp, ityp; + int ngrps, ntyps; #endif ndims = listlength(dimdefs); @@ -844,7 +847,7 @@ Generate the C code for defining a given type static void genc_deftype(Symbol* tsym) { - int i; + size_t i; ASSERT(tsym->objectclass == NC_TYPE); switch (tsym->subclass) { @@ -1032,8 +1035,7 @@ genc_writevar(Generator* generator, Symbol* vsym, Bytebuffer* code, /* Dump any vlen decls first */ generator_getstate(generator,(void**)&vlendecls); if(vlendecls != NULL && listlength(vlendecls) > 0) { - int i; - for(i=0;i 0) { - int i; - for(i=0;ivalue.int8v); break; case NC_UBYTE: - bbAppend(databuf,con->value.uint8v); + bbAppend(databuf,(char)con->value.uint8v); break; case NC_STRING: constsize = con->value.stringv.len; diff --git a/ncgen/semantics.c b/ncgen/semantics.c index 307e3deb54..1061ac8795 100644 --- a/ncgen/semantics.c +++ b/ncgen/semantics.c @@ -1338,7 +1338,7 @@ explode(NCConstant* con) len = con->value.stringv.len; chars = builddatalist(len); p = con->value.stringv.stringv; -fprintf(stderr,"p[%d]=|%s|\n",con->value.stringv.len,p); +fprintf(stderr,"p[%zu]=|%s|\n",con->value.stringv.len,p); for(i=0;inctype = NC_CHAR; diff --git a/ncgen/util.c b/ncgen/util.c index e5c73362d4..5b40dd0bbe 100644 --- a/ncgen/util.c +++ b/ncgen/util.c @@ -374,7 +374,7 @@ prefixtostring(List* prefix, char* separator) { size_t slen=0; int plen; - int i; + size_t i; char* result; if(prefix == NULL) return pooldup(""); plen = prefixlen(prefix); @@ -439,11 +439,10 @@ List* prefixdup(List* prefix) { List* dupseq; - int i; if(prefix == NULL) return listnew(); dupseq = listnew(); listsetalloc(dupseq, (size_t)listlength(prefix)); - for(i=0;i Date: Thu, 30 Nov 2023 18:01:53 +0000 Subject: [PATCH 05/16] Use `char` consistently for `fillchar` in `genchar.c` --- ncgen/genchar.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ncgen/genchar.c b/ncgen/genchar.c index 320473c527..b888c13670 100644 --- a/ncgen/genchar.c +++ b/ncgen/genchar.c @@ -12,9 +12,9 @@ /******************************************************/ /*Forward*/ -static size_t gen_charconstant(NCConstant*, Bytebuffer*, int fillchar); -static int getfillchar(Datalist* fillsrc); -static void gen_leafchararray(Dimset*,int,Datalist*,Bytebuffer*, int); +static size_t gen_charconstant(NCConstant*, Bytebuffer*, char fillchar); +static char getfillchar(Datalist* fillsrc); +static void gen_leafchararray(Dimset*,int,Datalist*,Bytebuffer*, char); static NCConstant* makeconst(int lineno, size_t len, char* str); static void rebuildsingletons(Datalist* data); @@ -54,7 +54,7 @@ Two special cases: void gen_chararray(Dimset* dimset, int dimindex, Datalist* data, Bytebuffer* charbuf, Datalist* fillsrc) { - int fillchar = getfillchar(fillsrc); + char fillchar = getfillchar(fillsrc); int rank = rankfor(dimset); int firstunlim = findunlimited(dimset,0); int nunlim = countunlimited(dimset); @@ -95,7 +95,7 @@ gen_chararray(Dimset* dimset, int dimindex, Datalist* data, Bytebuffer* charbuf, static void gen_leafchararray(Dimset* dimset, int dimindex, Datalist* data, - Bytebuffer* charbuf, int fillchar) + Bytebuffer* charbuf, char fillchar) { int i; size_t expectedsize,xproduct,unitsize; @@ -206,7 +206,7 @@ gen_charseq(Datalist* data, Bytebuffer* databuf) } static size_t -gen_charconstant(NCConstant* con, Bytebuffer* databuf, int fillchar) +gen_charconstant(NCConstant* con, Bytebuffer* databuf, char fillchar) { /* Following cases should be consistent with isstringable */ size_t constsize = 1; @@ -252,23 +252,21 @@ makeconst(int lineno, size_t len, char* str) return con; } -static int +static char getfillchar(Datalist* fillsrc) { /* Determine the fill char */ - int fillchar = 0; if(fillsrc != NULL && fillsrc->length > 0) { NCConstant* ccon = fillsrc->data[0]; if(ccon->nctype == NC_CHAR) { - fillchar = ccon->value.charv; + return ccon->value.charv; } else if(ccon->nctype == NC_STRING) { if(ccon->value.stringv.len > 0) { - fillchar = ccon->value.stringv.stringv[0]; + return ccon->value.stringv.stringv[0]; } } } - if(fillchar == 0) fillchar = NC_FILL_CHAR; /* default */ - return fillchar; + return NC_FILL_CHAR; /* default */ } From c1977cacc9e716761709f3d03fb9e94667232de2 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 1 Dec 2023 09:24:33 +0000 Subject: [PATCH 06/16] Fix some sign conversion warnings in ncgen --- ncgen/data.c | 3 +-- ncgen/dump.c | 4 ++-- ncgen/genc.c | 2 +- ncgen/genchar.c | 2 +- ncgen/generate.c | 7 ++++--- ncgen/genf77.c | 21 ++++++++++---------- ncgen/genj.c | 4 +++- ncgen/getfill.c | 6 +++--- ncgen/semantics.c | 50 +++++++++++++++++++---------------------------- ncgen/util.c | 4 ++-- ncgen/util.h | 3 ++- 11 files changed, 49 insertions(+), 57 deletions(-) diff --git a/ncgen/data.c b/ncgen/data.c index 19d6393b16..51c339bc4b 100644 --- a/ncgen/data.c +++ b/ncgen/data.c @@ -629,11 +629,10 @@ dlset(Datalist* dl, size_t pos, NCConstant* constant) NCConstant* dlremove(Datalist* dl, size_t pos) { - int i; NCConstant* con = NULL; ASSERT(dl->length > 0 && pos < dl->length); con = dl->data[pos]; - for(i=pos+1;ilength;i++) + for(size_t i=pos+1;ilength;i++) dl->data[i-1] = dl->data[i]; dl->length--; return con; diff --git a/ncgen/dump.c b/ncgen/dump.c index 004009840c..374d47ba15 100644 --- a/ncgen/dump.c +++ b/ncgen/dump.c @@ -6,6 +6,7 @@ /* $Header: /upc/share/CVS/netcdf-3/ncgen/dump.c,v 1.3 2010/05/24 19:59:57 dmh Exp $ */ #include "includes.h" +#include #include "dump.h" #undef DEBUGSRC @@ -51,14 +52,13 @@ bufdump(Datalist* list, Bytebuffer* buf) { int i; NCConstant** dpl; - unsigned int count; if(list == NULL) { bbCat(buf,"NULL"); return; } - count = list->length; + size_t count = list->length; for(dpl=list->data,i=0;inctype) { diff --git a/ncgen/genc.c b/ncgen/genc.c index 65aec192ab..0cab7aac2d 100644 --- a/ncgen/genc.c +++ b/ncgen/genc.c @@ -767,7 +767,7 @@ ctypename(Symbol* tsym) static void definectype(Symbol* tsym) { - int i,j; + size_t i,j; ASSERT(tsym->objectclass == NC_TYPE); switch (tsym->subclass) { diff --git a/ncgen/genchar.c b/ncgen/genchar.c index b888c13670..f7dd1b4565 100644 --- a/ncgen/genchar.c +++ b/ncgen/genchar.c @@ -284,7 +284,7 @@ rebuildsingletons(Datalist* data) } if(cccount > 1) { Bytebuffer* accum = bbNew(); - int len = 0; /* >0 implies doing accum */ + size_t len = 0; /* >0 implies doing accum */ Datalist* newlist = builddatalist(datalistlen(data)); int lineno = 0; NCConstant* con; diff --git a/ncgen/generate.c b/ncgen/generate.c index 339993233d..5c4d7070bd 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -116,7 +116,8 @@ generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist* break; case NC_COMPOUND: { - int i,uid, nfields, dllen; + size_t i, dllen; + int uid, nfields; if(con == NULL || isfillconst(con)) { Datalist* fill = (filler==NULL?getfiller(tsym):filler); ASSERT(fill->length == 1); @@ -212,7 +213,7 @@ static void generate_fieldarray(Symbol* basetype, NCConstant* con, Dimset* dimset, Bytebuffer* codebuf, Datalist* filler, Generator* generator) { - int i; + size_t i; int chartype = (basetype->typ.typecode == NC_CHAR); Datalist* data; int rank = rankfor(dimset); @@ -372,7 +373,7 @@ struct Args { }; static void -generate_arrayR(struct Args* args, int dimindex, size_t* index, Datalist* data) +generate_arrayR(struct Args* args, size_t dimindex, size_t* index, Datalist* data) { size_t counter,stop; size_t count[NC_MAX_VAR_DIMS]; diff --git a/ncgen/genf77.c b/ncgen/genf77.c index 89c20ed076..22f0beea06 100644 --- a/ncgen/genf77.c +++ b/ncgen/genf77.c @@ -5,6 +5,7 @@ *********************************************************************/ #include "includes.h" +#include #ifdef ENABLE_F77 @@ -46,7 +47,7 @@ static void genf77_writeattr(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*) void genf77_netcdf(void) { - int idim, ivar, iatt; + size_t idim, ivar, iatt; int ndims, nvars, natts, ngatts; char* cmode_string; const char *filename = rootgroup->file.filename; @@ -170,12 +171,12 @@ genf77_netcdf(void) /* F77 (as defined for ncgen3) requires per-type vectors for attributes */ if(ngatts > 0 || natts > 0) { nc_type nctype; - int pertypesizes[NC_DOUBLE+1]; + size_t pertypesizes[NC_DOUBLE+1]; for(nctype=0;nctype<=NC_DOUBLE;nctype++) {pertypesizes[nctype] = 0;} if(ngatts > 0) { for(iatt = 0; iatt < ngatts; iatt++) { Symbol* gasym = (Symbol*)listget(gattdefs,iatt); - int count = gasym->data->length; + size_t count = gasym->data->length; int typecode = gasym->typ.basetype->typ.typecode; if(count == 0) continue; if(pertypesizes[typecode] < count) @@ -185,7 +186,7 @@ genf77_netcdf(void) if(natts > 0) { for(iatt = 0; iatt < natts; iatt++) { Symbol* asym = (Symbol*)listget(attdefs,iatt); - int count = asym->data->length; + size_t count = asym->data->length; int typecode = asym->typ.basetype->typ.typecode; if(count == 0) continue; if(pertypesizes[typecode] < count) @@ -254,7 +255,7 @@ genf77_netcdf(void) if(dimset->ndims > 0) { /* Remember; FORTRAN dimension order is reversed */ for(idim = 0; idim < dimset->ndims; idim++) { - int reverse = (dimset->ndims - idim) - 1; + int reverse = (dimset->ndims - (int)idim) - 1; Symbol* dsym = dimset->dimsyms[reverse]; bbprintf0(stmt, "%s_dims(%d) = %s\n", @@ -336,7 +337,6 @@ genf77_netcdf(void) f77skip(); f77comment("perform variable data writes"); for(ivar = 0; ivar < nvars; ivar++) { - int i; Symbol* vsym = (Symbol*)listget(vardefs,ivar); /* Call the procedures for writing unlimited variables */ if(vsym->data != NULL @@ -346,7 +346,7 @@ genf77_netcdf(void) /* dump any calls */ generator_getstate(f77_generator,(void*)&calllist); ASSERT(calllist != NULL); - for(i=0;i 0) { - int i; f77skip(); - for(i=0;i #ifdef ENABLE_JAVA @@ -39,7 +40,8 @@ static void genj_writeattr(Generator*,Symbol*,Bytebuffer*,int,size_t*,size_t*); void genjava_netcdf(void) { - int idim, ivar, iatt, maxdims; + size_t idim, ivar, iatt; + int maxdims; int ndims, nvars, natts, ngatts; const char *filename = rootgroup->file.filename; diff --git a/ncgen/getfill.c b/ncgen/getfill.c index 745de59392..0fd0659807 100644 --- a/ncgen/getfill.c +++ b/ncgen/getfill.c @@ -6,6 +6,7 @@ #include "includes.h" #include "dump.h" +#include /* mnemonic*/ #define TOPLEVEL 1 @@ -110,7 +111,6 @@ fill(Symbol* tsym, Datalist* filler) static void filllist(Symbol* tsym, Datalist* dl) { - int i; Datalist* sublist; NCConstant* con = NULL; @@ -124,7 +124,7 @@ filllist(Symbol* tsym, Datalist* dl) break; case NC_COMPOUND: sublist = builddatalist(listlength(tsym->subnodes)); - for(i=0;isubnodes);i++) { + for(size_t i=0;isubnodes);i++) { Symbol* field = (Symbol*)listget(tsym->subnodes,i); filllist(field->typ.basetype,sublist); } @@ -149,7 +149,7 @@ fillarray(Symbol* basetype, Dimset* dimset, int index, Datalist* arraylist) { int i; Symbol* dim = dimset->dimsyms[index]; - unsigned int size = dim->dim.declsize; + size_t size = dim->dim.declsize; int isunlimited = (size == 0); int lastdim = (index == (dimset->ndims - 1)); diff --git a/ncgen/semantics.c b/ncgen/semantics.c index 1061ac8795..d950c7f39b 100644 --- a/ncgen/semantics.c +++ b/ncgen/semantics.c @@ -10,6 +10,7 @@ #include "ncoffsets.h" #include "netcdf_aux.h" #include "ncpathmgr.h" +#include #define floordiv(x,y) ((x) / (y)) #define ceildiv(x,y) (((x) % (y)) == 0 ? ((x) / (y)) : (((x) / (y)) + 1)) @@ -391,8 +392,7 @@ tagvlentypes(Symbol* tsym) static void filltypecodes(void) { - int i; - for(i=0;ityp.basetype != NULL && sym->typ.typecode == NC_NAT) sym->typ.typecode = sym->typ.basetype->typ.typecode; @@ -508,9 +508,8 @@ orderedtypes(Symbol* avsym, nc_type typ, List* types) } /* walk up the containing groups and collect type */ for(;container!= NULL;container = container->container) { - int i; /* Walk types in the container */ - for(i=0;isubnodes);i++) { + for(size_t i=0;isubnodes);i++) { Symbol* sym = (Symbol*)listget(container->subnodes,i); if(sym->objectclass == NC_TYPE && (typ == NC_NAT || sym->subclass == typ)) listpush(types,sym); @@ -523,8 +522,7 @@ orderedtypes(Symbol* avsym, nc_type typ, List* types) static Symbol* locateeconst(Symbol* enumt, const char* ecname) { - int i; - for(i=0;isubnodes);i++) { + for(size_t i=0;isubnodes);i++) { Symbol* esym = (Symbol*)listget(enumt->subnodes,i); ASSERT(esym->subclass == NC_ECONST); if(strcmp(esym->name,ecname)==0) @@ -536,7 +534,6 @@ locateeconst(Symbol* enumt, const char* ecname) static Symbol* findeconstenum(Symbol* avsym, NCConstant* con) { - int i; Symbol* refsym = con->value.enumv; List* typdefs = listnew(); Symbol* enumt = NULL; @@ -558,7 +555,7 @@ findeconstenum(Symbol* avsym, NCConstant* con) } else name = refsym->name; /* See if we can find the enum type */ - for(i=0;iobjectclass == NC_TYPE && sym->subclass == NC_ENUM); if(path != NULL && strcmp(sym->name,path)==0) {enumt = sym; break;} @@ -592,9 +589,6 @@ fixeconstref(Symbol* avsym, NCConstant* con) void computesize(Symbol* tsym) { - int i; - int offset = 0; - int largealign; unsigned long totaldimsize; if(tsym->touched) return; tsym->touched=1; @@ -622,20 +616,20 @@ computesize(Symbol* tsym) break; case NC_COMPOUND: /* keep if all fields are primitive*/ /* First, compute recursively, the size and alignment of fields*/ - for(i=0;isubnodes);i++) { + for(size_t i=0;isubnodes);i++) { Symbol* field = (Symbol*)listget(tsym->subnodes,i); ASSERT(field->subclass == NC_FIELD); computesize(field); if(i==0) tsym->typ.alignment = field->typ.alignment; } /* now compute the size of the compound based on what user specified*/ - offset = 0; - largealign = 1; - for(i=0;isubnodes);i++) { + size_t offset = 0; + size_t largealign = 1; + for(size_t i=0;isubnodes);i++) { Symbol* field = (Symbol*)listget(tsym->subnodes,i); /* only support 'c' alignment for now*/ - int alignment = field->typ.alignment; - int padding = getpadding(offset,alignment); + size_t alignment = field->typ.alignment; + size_t padding = getpadding(offset, alignment); offset += padding; field->typ.offset = offset; offset += field->typ.size; @@ -669,8 +663,7 @@ computesize(Symbol* tsym) void processvars(void) { - int i,j; - for(i=0;ityp.basetype; /* If we are in classic mode, then convert long -> int32 */ @@ -684,7 +677,7 @@ processvars(void) vsym->typ.typecode = basetype->typ.typecode; /* validate uses of NIL */ validateNIL(vsym); - for(j=0;jtyp.dimset.ndims;j++) { + for(size_t j=0;jtyp.dimset.ndims;j++) { /* validate the dimensions*/ /* UNLIMITED must only be in first place if using classic */ if(vsym->typ.dimset.dimsyms[j]->dim.declsize == NC_UNLIMITED) { @@ -698,7 +691,7 @@ processvars(void) static void processtypesizes(void) { - int i; + size_t i; /* use touch flag to avoid circularity*/ for(i=0;isubnodes);i++) { + for(size_t i=0;isubnodes);i++) { Symbol* sym = (Symbol*)listget(grp->subnodes,i); if(sym->ref.is_ref) continue; if(sym->objectclass != objectclass) continue; @@ -1020,9 +1012,8 @@ nctypesize( static int sqContains(List* seq, Symbol* sym) { - int i; if(seq == NULL) return 0; - for(i=0;iname, static void processunlimiteddims(void) { - int i; + size_t i; /* Set all unlimited dims to size 0; */ for(i=0;idata == NULL) continue; diff --git a/ncgen/util.c b/ncgen/util.c index 5b40dd0bbe..4f4ef2511e 100644 --- a/ncgen/util.c +++ b/ncgen/util.c @@ -203,7 +203,7 @@ ncclassname(nc_class ncc) return s; } -int ncsizes[17] = { +size_t ncsizes[17] = { 0, 1,1,2,4, 4,8, @@ -214,7 +214,7 @@ sizeof(nc_vlen_t), 0,0,0 }; -int +size_t ncsize(nc_type nctype) { if(nctype >= NC_NAT && nctype <= NC_COMPOUND) diff --git a/ncgen/util.h b/ncgen/util.h index 71528ecdfc..5cafb09187 100644 --- a/ncgen/util.h +++ b/ncgen/util.h @@ -6,6 +6,7 @@ * $Header: /upc/share/CVS/netcdf-3/ncgen/util.h,v 1.3 2010/04/04 19:39:57 dmh Exp $ *********************************************************************/ +#include #define MAX(x,y) ((x)>(y)?(x):(y)) extern void expe2d(char*); @@ -24,7 +25,7 @@ extern int classicunlimited(Dimset* dimset); extern int isbounded(Dimset* dimset); extern char* nctypename(nc_type); extern char* ncclassname(nc_class); -extern int ncsize(nc_type); +extern size_t ncsize(nc_type); extern nc_type signedtype(nc_type nctype); extern nc_type unsignedtype(nc_type nctype); From 506a09df7ed41681df0e95c47561bb8c3c6a5cab Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 8 Dec 2023 16:17:59 +0000 Subject: [PATCH 07/16] Try to be more consistent with types of alignments/offsets --- ncgen/bindata.c | 26 ++++++++++++-------------- ncgen/data.c | 2 +- ncgen/generate.c | 2 +- ncgen/util.c | 9 ++++----- ncgen/util.h | 2 +- 5 files changed, 19 insertions(+), 22 deletions(-) diff --git a/ncgen/bindata.c b/ncgen/bindata.c index 5469ff2e21..8a06be89ec 100644 --- a/ncgen/bindata.c +++ b/ncgen/bindata.c @@ -10,7 +10,7 @@ #ifdef ENABLE_BINARY /* Forward */ -static void alignto(int alignment, Bytebuffer* buf, ptrdiff_t base); +static void alignto(size_t alignment, Bytebuffer* buf, size_t base); static int bin_uid = 0; @@ -105,7 +105,7 @@ bin_listbegin(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, { if(uidp) *uidp = ++bin_uid; if(lc == LISTCOMPOUND) - *((int*)liststate) = (int)bbLength(buf); + *((size_t*)liststate) = bbLength(buf); return 1; } @@ -113,9 +113,9 @@ static int bin_list(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, int uid, size_t count, Bytebuffer* buf, ...) { if(lc == LISTCOMPOUND) { - int offsetbase = *((int*)liststate); + size_t offsetbase = *((size_t*)liststate); /* Pad for the alignment */ - alignto(tsym->typ.alignment,buf,offsetbase); + alignto(tsym->typ.alignment,buf,offsetbase); } return 1; } @@ -124,7 +124,7 @@ static int bin_listend(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, int uid, size_t count, Bytebuffer* buf, ...) { if(lc == LISTCOMPOUND) { - int offsetbase = *((int*)liststate); + size_t offsetbase = *((size_t*)liststate); /* Pad out the whole instance */ alignto(tsym->typ.cmpdalign,buf,offsetbase); } @@ -167,12 +167,11 @@ static const char zeros[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; static void -alignto(int alignment, Bytebuffer* buf, ptrdiff_t base) +alignto(size_t alignment, Bytebuffer* buf, size_t base) { - int pad = 0; - ptrdiff_t offset = bbLength(buf); - offset -= base; /* Need to actually align wrt to the base */ - pad = getpadding(offset,alignment); + /* Need to actually align wrt to the base */ + size_t offset = bbLength(buf) - base; + size_t pad = getpadding(offset,alignment); if(pad > 0) { bbAppendn(buf,(void*)zeros,pad); } @@ -196,11 +195,10 @@ Generator* bin_generator = &bin_generator_singleton; static int bin_generate_data_r(NCConstant* instance, Symbol* tsym, Datalist* fillvalue, Bytebuffer* databuf); static void -write_alignment(int alignment, Bytebuffer* buf) +write_alignment(size_t alignment, Bytebuffer* buf) { - int pad = 0; - ptrdiff_t offset = bbLength(buf); - pad = getpadding(offset,alignment); + unsigned int offset = bbLength(buf); + size_t pad = getpadding(offset,alignment); if(pad > 0) { bbAppendn(buf,(void*)zeros,pad); } diff --git a/ncgen/data.c b/ncgen/data.c index 51c339bc4b..513248848d 100644 --- a/ncgen/data.c +++ b/ncgen/data.c @@ -309,7 +309,7 @@ alignbuffer(NCConstant* prim, Bytebuffer* buf) { int stat = NC_NOERR; size_t alignment; - int pad,offset; + size_t pad,offset; ASSERT(prim->nctype != NC_COMPOUND); diff --git a/ncgen/generate.c b/ncgen/generate.c index 5c4d7070bd..bb5846644e 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -97,7 +97,7 @@ void generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist* filler, Generator* generator) { Datalist* data; - int offsetbase = 0; + size_t offsetbase = 0; switch (tsym->subclass) { diff --git a/ncgen/util.c b/ncgen/util.c index 4f4ef2511e..3802d32f91 100644 --- a/ncgen/util.c +++ b/ncgen/util.c @@ -524,12 +524,11 @@ makebytestring(char* s, size_t* lenp) return bytes; } -int -getpadding(int offset, int alignment) +size_t +getpadding(size_t offset, size_t alignment) { - int rem = (alignment==0?0:(offset % alignment)); - int pad = (rem==0?0:(alignment - rem)); - return pad; + size_t rem = (alignment==0 ? 0 : (offset % alignment)); + return rem == 0 ? 0 : (alignment - rem); } static void diff --git a/ncgen/util.h b/ncgen/util.h index 5cafb09187..f6defb005d 100644 --- a/ncgen/util.h +++ b/ncgen/util.h @@ -57,7 +57,7 @@ extern int findlastunlimited(Dimset* dimset); extern int countunlimited(Dimset* dimset); extern unsigned char* makebytestring(char* s, size_t* lenp); -extern int getpadding(int offset, int alignment); +extern size_t getpadding(size_t offset, size_t alignment); extern void check_err(const int stat, const int line, const char* file, const char* func); extern void check_err2(const int stat, const int cdlline, const int line, const char* file, const char* func); From a90730c4025440cd50943f8a50cb2484fb594ca2 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Fri, 8 Dec 2023 16:52:40 +0000 Subject: [PATCH 08/16] Try to be more consistent in `char` type for escaping characters --- ncgen/escapes.c | 16 ++++++++-------- ncgen/genlib.h | 8 ++++---- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ncgen/escapes.c b/ncgen/escapes.c index 2b7ff86422..807b428086 100644 --- a/ncgen/escapes.c +++ b/ncgen/escapes.c @@ -27,7 +27,7 @@ Returns s as its result. */ char* -escapifychar(unsigned int c, char* s0, int quote) +escapifychar(char c, char* s0, int quote) { char* s = s0; if(c == '\\') { @@ -47,9 +47,9 @@ escapifychar(unsigned int c, char* s0, int quote) case '\t': strcpy(s,"\\t"); s+=2; break; case '\v': strcpy(s,"\\v"); s+=2; break; default: { - unsigned int oct1 = (c & 007); - unsigned int oct2 = ((c >> 3) & 007); - unsigned int oct3 = ((c >> 6) & 003); + char oct1 = (c & 007); + char oct2 = ((c >> 3) & 007); + char oct3 = ((c >> 6) & 003); *s++ = '\\'; *s++ = oct3 + '0'; *s++ = oct2 + '0'; @@ -67,7 +67,7 @@ escapifychar(unsigned int c, char* s0, int quote) /* Since the string might actually contain nulls, specify the length.*/ char* -escapify(char* s0, int quote, size_t len) +escapify(const char* s0, int quote, size_t len) { int i; char* result; @@ -75,14 +75,14 @@ escapify(char* s0, int quote, size_t len) result[0] = '\0'; for(i=0;i Date: Fri, 8 Dec 2023 17:13:32 +0000 Subject: [PATCH 09/16] Remove unused function from ncgen/dump.c --- ncgen/dump.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ncgen/dump.c b/ncgen/dump.c index 374d47ba15..c8ffc63803 100644 --- a/ncgen/dump.c +++ b/ncgen/dump.c @@ -17,16 +17,6 @@ /* Forward */ static void dumpdataprim(NCConstant*,Bytebuffer*); -char* -indentstr(int n) -{ - static char indentline[1024]; - memset(indentline,' ',n+1); - indentline[n+1] = '\0'; - return indentline; -} - - void dumpconstant(NCConstant* con, char* tag) { From 6b17d77e7a79d41d5e0385eeafda4a6a460ee997 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 11 Dec 2023 13:38:25 +0000 Subject: [PATCH 10/16] Fix some size/conversion warnings in ncgen.l/y --- ncgen/ncgen.l | 12 ++++++------ ncgen/ncgen.y | 27 +++++++++++++-------------- ncgen/ncgenl.c | 12 ++++++------ ncgen/ncgeny.c | 27 ++++++++++++++------------- ncgen/ncgeny.h | 2 +- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/ncgen/ncgen.l b/ncgen/ncgen.l index 963ecefcca..ffc035e90d 100644 --- a/ncgen/ncgen.l +++ b/ncgen/ncgen.l @@ -376,7 +376,7 @@ NIL|nil|Nil { return lexdebug(DATASETID); } -{ID} { char* id = NULL; int len; +{ID} { char* id = NULL; size_t len; len = strlen(yytext); len = unescape(yytext,len,ISIDENT,&id); if(NCSTREQ(id, FILL_STRING)) { @@ -395,7 +395,7 @@ NIL|nil|Nil { If out of any integer range, then complain Also, if the digits begin with 0, then assume octal. */ - int slen = strlen(ncgtext); + size_t slen = strlen(ncgtext); char* stag = NULL; int tag = NC_NAT; int isneg = 0; @@ -469,11 +469,11 @@ done: return 0; {XUNUMBER} { int c; int token = 0; - int slen = strlen(yytext); + size_t slen = strlen(yytext); char* stag = NULL; int tag = NC_NAT; char* hex = yytext+2; /* point to first true hex digit */ - int xlen = (slen - 3); /* true hex length */ + size_t xlen = (slen - 3); /* true hex length */ yytext[slen-1] = '\0'; /* capture the tag string */ @@ -842,8 +842,8 @@ collecttag(char* text, char** stagp) char* stag0; #define MAXTAGLEN 3 char stag[MAXTAGLEN+1]; - int slen = strlen(text); - int staglen; + size_t slen = strlen(text); + size_t staglen; int tag = NC_NAT; int hasU = 0; diff --git a/ncgen/ncgen.y b/ncgen/ncgen.y index c8c2d5ac62..3610f3576b 100644 --- a/ncgen/ncgen.y +++ b/ncgen/ncgen.y @@ -66,9 +66,9 @@ static List* stack; static nc_type consttype; /* Misc. */ -static int stackbase; -static int stacklen; -static int count; +static size_t stackbase; +static size_t stacklen; +static size_t count; static int opaqueid; /* counter for opaque constants*/ static int arrayuid; /* counter for pseudo-array types*/ @@ -156,7 +156,7 @@ extern int lex_init(void); %union { Symbol* sym; unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/ -long mark; /* track indices into the sequence*/ +size_t mark; /* track indices into the sequence*/ int nctype; /* for tracking attribute list type*/ Datalist* datalist; NCConstant* constant; @@ -312,7 +312,7 @@ optsemicolon: /*empty*/ | ';' ; enumdecl: primtype ENUM typename '{' enumidlist '}' { - int i; + size_t i; addtogroup($3); /* sets prefix*/ $3->objectclass=NC_TYPE; $3->subclass=NC_ENUM; @@ -343,7 +343,7 @@ enumidlist: enumid {$$=listlength(stack); listpush(stack,(void*)$1);} | enumidlist ',' enumid { - int i; + size_t i; $$=$1; /* check for duplicates*/ stackbase=$1; @@ -395,7 +395,7 @@ vlendecl: typeref '(' '*' ')' typename compounddecl: COMPOUND typename '{' fields '}' { - int i,j; + size_t i,j; vercheck(NC_COMPOUND); addtogroup($2); /* check for duplicate field names*/ @@ -432,7 +432,7 @@ fields: field ';' {$$=$1;} field: typeref fieldlist { - int i; + size_t i; $$=$2; stackbase=$2; stacklen=listlength(stack); @@ -517,7 +517,7 @@ vadecl_or_attr: vardecl {} | attrdecl {} ; vardecl: typeref varlist { - int i; + size_t i; stackbase=$2; stacklen=listlength(stack); /* process each variable in the varlist*/ @@ -547,7 +547,7 @@ varlist: varspec varspec: varident dimspec { - int i; + size_t i; Dimset dimset; Symbol* var = $1; /* for debugging */ stacklen=listlength(stack); @@ -608,7 +608,7 @@ fieldlist: fieldspec: ident fielddimspec { - int i; + size_t i; Dimset dimset; stackbase=$2; stacklen=listlength(stack); @@ -1082,8 +1082,7 @@ makeconstdata(nc_type nctype) #ifdef USE_NETCDF4 case NC_OPAQUE: { char* s; - int len; - len = bbLength(lextext); + size_t len = bbLength(lextext); s = (char*)ecalloc(len+1); strncpy(s,bbContents(lextext),len); s[len] = '\0'; @@ -1136,7 +1135,7 @@ addtogroup(Symbol* sym) static int dupobjectcheck(nc_class objectclass, Symbol* pattern) { - int i; + size_t i; Symbol* grp; if(pattern == NULL) return 0; grp = pattern->container; diff --git a/ncgen/ncgenl.c b/ncgen/ncgenl.c index 54596c8f73..860063fed5 100644 --- a/ncgen/ncgenl.c +++ b/ncgen/ncgenl.c @@ -2347,7 +2347,7 @@ YY_RULE_SETUP case 40: YY_RULE_SETUP #line 379 "ncgen/ncgen.l" -{ char* id = NULL; int len; +{ char* id = NULL; size_t len; len = strlen(yytext); len = unescape(yytext,len,ISIDENT,&id); if(NCSTREQ(id, FILL_STRING)) { @@ -2369,7 +2369,7 @@ YY_RULE_SETUP If out of any integer range, then complain Also, if the digits begin with 0, then assume octal. */ - int slen = strlen(ncgtext); + size_t slen = strlen(ncgtext); char* stag = NULL; int tag = NC_NAT; int isneg = 0; @@ -2446,11 +2446,11 @@ YY_RULE_SETUP { int c; int token = 0; - int slen = strlen(yytext); + size_t slen = strlen(yytext); char* stag = NULL; int tag = NC_NAT; char* hex = yytext+2; /* point to first true hex digit */ - int xlen = (slen - 3); /* true hex length */ + size_t xlen = (slen - 3); /* true hex length */ yytext[slen-1] = '\0'; /* capture the tag string */ @@ -3876,8 +3876,8 @@ collecttag(char* text, char** stagp) char* stag0; #define MAXTAGLEN 3 char stag[MAXTAGLEN+1]; - int slen = strlen(text); - int staglen; + size_t slen = strlen(text); + size_t staglen; int tag = NC_NAT; int hasU = 0; diff --git a/ncgen/ncgeny.c b/ncgen/ncgeny.c index 2fd6ea19aa..d9f4074137 100644 --- a/ncgen/ncgeny.c +++ b/ncgen/ncgeny.c @@ -133,9 +133,9 @@ static List* stack; static nc_type consttype; /* Misc. */ -static int stackbase; -static int stacklen; -static int count; +static size_t stackbase; +static size_t stacklen; +static size_t count; static int opaqueid; /* counter for opaque constants*/ static int arrayuid; /* counter for pseudo-array types*/ @@ -1913,7 +1913,7 @@ yyparse (void) case 25: /* enumdecl: primtype ENUM typename '{' enumidlist '}' */ #line 314 "ncgen/ncgen.y" { - int i; + size_t i; addtogroup((yyvsp[-3].sym)); /* sets prefix*/ (yyvsp[-3].sym)->objectclass=NC_TYPE; (yyvsp[-3].sym)->subclass=NC_ENUM; @@ -1950,7 +1950,7 @@ yyparse (void) case 27: /* enumidlist: enumidlist ',' enumid */ #line 345 "ncgen/ncgen.y" { - int i; + size_t i; (yyval.mark)=(yyvsp[-2].mark); /* check for duplicates*/ stackbase=(yyvsp[-2].mark); @@ -2010,7 +2010,7 @@ yyparse (void) case 31: /* compounddecl: COMPOUND typename '{' fields '}' */ #line 397 "ncgen/ncgen.y" { - int i,j; + size_t i,j; vercheck(NC_COMPOUND); addtogroup((yyvsp[-3].sym)); /* check for duplicate field names*/ @@ -2056,7 +2056,7 @@ yyparse (void) case 34: /* field: typeref fieldlist */ #line 434 "ncgen/ncgen.y" { - int i; + size_t i; (yyval.mark)=(yyvsp[0].mark); stackbase=(yyvsp[0].mark); stacklen=listlength(stack); @@ -2230,7 +2230,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); case 66: /* vardecl: typeref varlist */ #line 519 "ncgen/ncgen.y" { - int i; + size_t i; stackbase=(yyvsp[0].mark); stacklen=listlength(stack); /* process each variable in the varlist*/ @@ -2268,7 +2268,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); case 69: /* varspec: varident dimspec */ #line 549 "ncgen/ncgen.y" { - int i; + size_t i; Dimset dimset; Symbol* var = (yyvsp[-1].sym); /* for debugging */ stacklen=listlength(stack); @@ -2352,7 +2352,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); case 77: /* fieldspec: ident fielddimspec */ #line 610 "ncgen/ncgen.y" { - int i; + size_t i; Dimset dimset; stackbase=(yyvsp[0].mark); stacklen=listlength(stack); @@ -3318,12 +3318,13 @@ makeconstdata(nc_type nctype) #ifdef USE_NETCDF4 case NC_OPAQUE: { char* s; - size_t len = bbLength(lextext); + size_t len; + len = bbLength(lextext); s = (char*)ecalloc(len+1); strncpy(s,bbContents(lextext),len); s[len] = '\0'; con->value.opaquev.stringv = s; - con->value.opaquev.len = (int)len; + con->value.opaquev.len = len; } break; case NC_NIL: @@ -3371,7 +3372,7 @@ addtogroup(Symbol* sym) static int dupobjectcheck(nc_class objectclass, Symbol* pattern) { - int i; + size_t i; Symbol* grp; if(pattern == NULL) return 0; grp = pattern->container; diff --git a/ncgen/ncgeny.h b/ncgen/ncgeny.h index 3b1821a7a0..09ce4d2aae 100644 --- a/ncgen/ncgeny.h +++ b/ncgen/ncgeny.h @@ -123,7 +123,7 @@ union YYSTYPE Symbol* sym; unsigned long size; /* allow for zero size to indicate e.g. UNLIMITED*/ -long mark; /* track indices into the sequence*/ +size_t mark; /* track indices into the sequence*/ int nctype; /* for tracking attribute list type*/ Datalist* datalist; NCConstant* constant; From 17a7b283016dfbc03331af2ca34a393b4c871f26 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 11 Dec 2023 13:41:17 +0000 Subject: [PATCH 11/16] Change type of opaque object length member --- ncgen/cdata.c | 2 +- ncgen/cvt.c | 4 ++-- ncgen/data.c | 4 ++-- ncgen/data.h | 2 +- ncgen/generate.c | 6 +++--- ncgen/ncgeny.c | 3 +-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ncgen/cdata.c b/ncgen/cdata.c index 0b9c2296f7..eccf86a07c 100644 --- a/ncgen/cdata.c +++ b/ncgen/cdata.c @@ -99,7 +99,7 @@ c_constant(Generator* generator, Symbol* sym, NCConstant* con, Bytebuffer* buf,. } break; case NC_OPAQUE: { char* p; - size_t bslen = (size_t)(4*con->value.opaquev.len); + size_t bslen = 4*con->value.opaquev.len; special = poolalloc(bslen+2+1); strcpy(special,"\""); p = con->value.opaquev.stringv; diff --git a/ncgen/cvt.c b/ncgen/cvt.c index b7daa7483b..aa1b4c4cb9 100644 --- a/ncgen/cvt.c +++ b/ncgen/cvt.c @@ -560,8 +560,8 @@ case CASE(NC_OPAQUE,NC_DOUBLE): tmp.doublev = *(double*)bytes; break; case CASE(NC_OPAQUE,NC_OPAQUE): - tmp.opaquev.stringv = (char*)ecalloc((size_t)src->value.opaquev.len+1); - memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv, (size_t)src->value.opaquev.len); + tmp.opaquev.stringv = (char*)ecalloc(src->value.opaquev.len+1); + memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv, src->value.opaquev.len); tmp.opaquev.len = src->value.opaquev.len; tmp.opaquev.stringv[tmp.opaquev.len] = '\0'; break; diff --git a/ncgen/data.c b/ncgen/data.c index 513248848d..a70572fb15 100644 --- a/ncgen/data.c +++ b/ncgen/data.c @@ -156,9 +156,9 @@ cloneconstant(NCConstant* con) newcon->value.stringv.stringv = s; break; case NC_OPAQUE: - s = (char*)ecalloc((size_t)newcon->value.opaquev.len+1); + s = (char*)ecalloc(newcon->value.opaquev.len+1); if(newcon->value.opaquev.len > 0) - memcpy(s,newcon->value.opaquev.stringv, (size_t)newcon->value.opaquev.len); + memcpy(s,newcon->value.opaquev.stringv, newcon->value.opaquev.len); s[newcon->value.opaquev.len] = '\0'; newcon->value.opaquev.stringv = s; break; diff --git a/ncgen/data.h b/ncgen/data.h index 8342a2d7b1..64566cec59 100644 --- a/ncgen/data.h +++ b/ncgen/data.h @@ -41,7 +41,7 @@ typedef union Constvalue { char* stringv; } stringv; struct Opaquev { /* NC_OPAQUE*/ - int len; /* length as originally written (rounded to even number)*/ + size_t len; /* length as originally written (rounded to even number)*/ char* stringv; /*as constant was written*/ /* (padded to even # chars >= 16)*/ /* without leading 0x*/ diff --git a/ncgen/generate.c b/ncgen/generate.c index bb5846644e..9121920957 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -259,16 +259,16 @@ normalizeopaquelength(NCConstant* prim, unsigned long nbytes) /* do nothing*/ } else if(prim->value.opaquev.len > nnibs) { /* truncate*/ prim->value.opaquev.stringv[nnibs] = '\0'; - prim->value.opaquev.len = (int)nnibs; + prim->value.opaquev.len = nnibs; } else {/* prim->value.opaquev.len < nnibs => expand*/ char* s; s = (char*)ecalloc(nnibs+1); memset(s,'0',nnibs); /* Fill with '0' characters */ - memcpy(s,prim->value.opaquev.stringv, (size_t)prim->value.opaquev.len); + memcpy(s,prim->value.opaquev.stringv, prim->value.opaquev.len); s[nnibs] = '\0'; efree(prim->value.opaquev.stringv); prim->value.opaquev.stringv=s; - prim->value.opaquev.len = (int)nnibs; + prim->value.opaquev.len = nnibs; } } diff --git a/ncgen/ncgeny.c b/ncgen/ncgeny.c index d9f4074137..bd6afd22cd 100644 --- a/ncgen/ncgeny.c +++ b/ncgen/ncgeny.c @@ -3318,8 +3318,7 @@ makeconstdata(nc_type nctype) #ifdef USE_NETCDF4 case NC_OPAQUE: { char* s; - size_t len; - len = bbLength(lextext); + size_t len = bbLength(lextext); s = (char*)ecalloc(len+1); strncpy(s,bbContents(lextext),len); s[len] = '\0'; From 3134af3ce7b304389043152fe4954122841fd761 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 11 Dec 2023 14:04:43 +0000 Subject: [PATCH 12/16] Remove unused static variable --- ncgen/escapes.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ncgen/escapes.c b/ncgen/escapes.c index 807b428086..f838e28474 100644 --- a/ncgen/escapes.c +++ b/ncgen/escapes.c @@ -117,7 +117,6 @@ cquotestring(Bytebuffer* databuf, char quote) static int init = 0; static char* repls[256]; /* replacement string for each char */ -static int lens[256]; /* lengths of replacement strings */ static struct { char c; char *s; @@ -186,9 +185,6 @@ initcodify(void) rp[hexlen] = '\0'; repls[i] = rp; } - for(i = 0; i < 256; i++) { - lens[i] = strlen(repls[i]); - } init = 1; /* only do this initialization once */ } From 47d1b68599313e4812111d8d9bf5addb0f4458fe Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 11 Dec 2023 14:08:55 +0000 Subject: [PATCH 13/16] Cast to correct type in assignment --- ncgen/genbin.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ncgen/genbin.c b/ncgen/genbin.c index 1e4193057c..9b447e4068 100644 --- a/ncgen/genbin.c +++ b/ncgen/genbin.c @@ -357,8 +357,7 @@ genbin_deftype(Symbol* tsym) int dimsizes[NC_MAX_VAR_DIMS]; /* int because inside compound */ /* Generate the field dimension constants*/ for(j=0;jtyp.dimset.ndims;j++) { - unsigned int size = efield->typ.dimset.dimsyms[j]->dim.declsize; - dimsizes[j] = size; + dimsizes[j] = (int)efield->typ.dimset.dimsyms[j]->dim.declsize; } stat = nc_insert_array_compound( tsym->container->nc_id, From 320c29c7237479a3eb44a7df5fdf91dbf55e8594 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 14 Mar 2024 14:34:31 +0000 Subject: [PATCH 14/16] Fix more sign conversion warnings in ncgen --- ncgen/bytebuffer.c | 4 ++-- ncgen/cvt.c | 2 +- ncgen/data.c | 18 ++++++++---------- ncgen/escapes.c | 8 ++++---- ncgen/genchar.c | 2 +- ncgen/generate.c | 6 +++--- ncgen/genf77.c | 2 +- ncgen/semantics.c | 2 +- ncgen/util.c | 6 +++--- 9 files changed, 24 insertions(+), 26 deletions(-) diff --git a/ncgen/bytebuffer.c b/ncgen/bytebuffer.c index 63bc50267d..16122ee634 100644 --- a/ncgen/bytebuffer.c +++ b/ncgen/bytebuffer.c @@ -152,7 +152,7 @@ bbAppendn(Bytebuffer* bb, const void* elem, const size_t n0) if(n == 0) {n = strlen((char*)elem);} while(!bbNeed(bb,(n+1))) {if(!bbSetalloc(bb,0)) return bbFail();} memcpy((void*)&bb->content[bb->length],(void*)elem,n); - bb->length += n; + bb->length += (unsigned int)n; bb->content[bb->length] = '\0'; return TRUE; } @@ -169,7 +169,7 @@ int bbInsertn(Bytebuffer* bb, const unsigned int index, const char* elem, const unsigned int n) { unsigned int i; - int j; + unsigned int j; unsigned int newlen = 0; if(bb == NULL) return bbFail(); diff --git a/ncgen/cvt.c b/ncgen/cvt.c index aa1b4c4cb9..e074390db9 100644 --- a/ncgen/cvt.c +++ b/ncgen/cvt.c @@ -640,7 +640,7 @@ convertstringtochars(NCConstant* str) char* s; size_t slen = str->value.stringv.len; - dl = builddatalist(slen); + dl = builddatalist((int)slen); s = str->value.stringv.stringv; for(i=0;i 0) memmove(&dl->data[pos+len2],&dl->data[pos], (size_t)delta*sizeof(NCConstant*)); dl->length += len2; - for(i=0;idata[i]; con = cloneconstant(con); dl->data[pos+i] = con; @@ -700,7 +699,7 @@ clonedatalist(Datalist* dl) if(dl == NULL) return NULL; len = datalistlen(dl); - newdl = builddatalist(len); + newdl = builddatalist((int)len); /* initialize */ for(i=0;i 1) { Bytebuffer* accum = bbNew(); size_t len = 0; /* >0 implies doing accum */ - Datalist* newlist = builddatalist(datalistlen(data)); + Datalist* newlist = builddatalist((int)datalistlen(data)); int lineno = 0; NCConstant* con; /* We are going to construct a single string constant for each diff --git a/ncgen/generate.c b/ncgen/generate.c index 9121920957..10843f3ea7 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -454,7 +454,7 @@ generate_array(Symbol* vsym, Bytebuffer* code, Datalist* filler, Generator* gene if(vsym->var.special._Storage == NC_CHUNKED) { if(vsym->var.special._ChunkSizes) - memcpy(args.chunksizes,vsym->var.special._ChunkSizes,sizeof(size_t)*args.rank); + memcpy(args.chunksizes,vsym->var.special._ChunkSizes,sizeof(size_t)*(size_t)args.rank); } memset(index,0,sizeof(index)); @@ -466,8 +466,8 @@ generate_array(Symbol* vsym, Bytebuffer* code, Datalist* filler, Generator* gene Bytebuffer* charbuf = bbNew(); gen_chararray(args.dimset,0,args.vsym->data,charbuf,args.filler); args.generator->charconstant(args.generator,args.vsym,args.code,charbuf); - memset(start,0,sizeof(size_t)*args.rank); - memcpy(count,args.dimsizes,sizeof(size_t)*args.rank); + memset(start,0,sizeof(size_t)*(size_t)args.rank); + memcpy(count,args.dimsizes,sizeof(size_t)*(size_t)args.rank); args.writer(args.generator,args.vsym,args.code,args.rank,start,count); bbFree(charbuf); bbClear(args.code); diff --git a/ncgen/genf77.c b/ncgen/genf77.c index 22f0beea06..497cf0d710 100644 --- a/ncgen/genf77.c +++ b/ncgen/genf77.c @@ -490,7 +490,7 @@ f77fold(Bytebuffer* lines) while(*linen != '\n' && *linen != '\0') linen++; if(*linen == '\0') break; linen++; /* include trailing newline */ - linelen = (linen - line0); + linelen = (size_t)(linen - line0); /* handle comments and empty lines */ if(*line0 == '*' || linelen == 1) { bbAppendn(lines,line0,linelen); diff --git a/ncgen/semantics.c b/ncgen/semantics.c index d950c7f39b..189047499e 100644 --- a/ncgen/semantics.c +++ b/ncgen/semantics.c @@ -1326,7 +1326,7 @@ explode(NCConstant* con) Datalist* chars; ASSERT((con->nctype == NC_STRING)); len = con->value.stringv.len; - chars = builddatalist(len); + chars = builddatalist((int)len); p = con->value.stringv.stringv; fprintf(stderr,"p[%zu]=|%s|\n",con->value.stringv.len,p); for(i=0;i Date: Thu, 14 Mar 2024 14:56:10 +0000 Subject: [PATCH 15/16] Fix return type of `listlength` --- ncgen/genbin.c | 17 ++++++----------- ncgen/genc.c | 14 ++++++-------- ncgen/generate.c | 4 ++-- ncgen/genf77.c | 11 +++++------ ncgen/genj.c | 9 ++++----- ncgen/getfill.c | 4 ++-- ncgen/list.h | 2 +- ncgen/util.c | 5 ++--- 8 files changed, 28 insertions(+), 38 deletions(-) diff --git a/ncgen/genbin.c b/ncgen/genbin.c index 9b447e4068..019ed52638 100644 --- a/ncgen/genbin.c +++ b/ncgen/genbin.c @@ -34,20 +34,15 @@ genbin_netcdf(void) { int stat, ncid; size_t idim, ivar, iatt; - int ndims, nvars, natts, ngatts; const char* filename = rootgroup->file.filename; + size_t ndims = listlength(dimdefs); + size_t nvars = listlength(vardefs); + size_t natts = listlength(attdefs); + size_t ngatts = listlength(gattdefs); #ifdef USE_NETCDF4 - int ntyps, ngrps; -#endif - - ndims = listlength(dimdefs); - nvars = listlength(vardefs); - natts = listlength(attdefs); - ngatts = listlength(gattdefs); -#ifdef USE_NETCDF4 - ntyps = listlength(typdefs); - ngrps = listlength(grpdefs); + size_t ntyps = listlength(typdefs); + size_t ngrps = listlength(grpdefs); #endif /*USE_NETCDF4*/ /* Turn on logging */ diff --git a/ncgen/genc.c b/ncgen/genc.c index 0cab7aac2d..fc16a78ddd 100644 --- a/ncgen/genc.c +++ b/ncgen/genc.c @@ -40,22 +40,20 @@ genc_netcdf(void) { size_t idim, ivar, iatt; int maxdims; - int ndims, nvars, natts, ngatts; char* cmode_string; const char *filename = rootgroup->file.filename; #ifdef USE_NETCDF4 size_t igrp, ityp; - int ngrps, ntyps; #endif - ndims = listlength(dimdefs); - nvars = listlength(vardefs); - natts = listlength(attdefs); - ngatts = listlength(gattdefs); + size_t ndims = listlength(dimdefs); + size_t nvars = listlength(vardefs); + size_t natts = listlength(attdefs); + size_t ngatts = listlength(gattdefs); #ifdef USE_NETCDF4 - ngrps = listlength(grpdefs); - ntyps = listlength(typdefs); + size_t ngrps = listlength(grpdefs); + size_t ntyps = listlength(typdefs); #endif /*USE_NETCDF4*/ /* wrap in main program */ diff --git a/ncgen/generate.c b/ncgen/generate.c index 10843f3ea7..2b21d82f2f 100644 --- a/ncgen/generate.c +++ b/ncgen/generate.c @@ -117,7 +117,7 @@ generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist* case NC_COMPOUND: { size_t i, dllen; - int uid, nfields; + int uid; if(con == NULL || isfillconst(con)) { Datalist* fill = (filler==NULL?getfiller(tsym):filler); ASSERT(fill->length == 1); @@ -140,7 +140,7 @@ generate_basetype(Symbol* tsym, NCConstant* con, Bytebuffer* codebuf, Datalist* } data = con->value.compoundv; - nfields = listlength(tsym->subnodes); + size_t nfields = listlength(tsym->subnodes); dllen = datalistlen(data); if(dllen > nfields) { semerror(con->lineno,"Datalist longer than the number of compound fields"); diff --git a/ncgen/genf77.c b/ncgen/genf77.c index 497cf0d710..ef8fd136d0 100644 --- a/ncgen/genf77.c +++ b/ncgen/genf77.c @@ -48,14 +48,13 @@ void genf77_netcdf(void) { size_t idim, ivar, iatt; - int ndims, nvars, natts, ngatts; char* cmode_string; const char *filename = rootgroup->file.filename; - ndims = listlength(dimdefs); - nvars = listlength(vardefs); - natts = listlength(attdefs); - ngatts = listlength(gattdefs); + size_t ndims = listlength(dimdefs); + size_t nvars = listlength(vardefs); + size_t natts = listlength(attdefs); + size_t ngatts = listlength(gattdefs); /* Construct the main program */ @@ -708,7 +707,7 @@ genf77_writevar(Generator* generator, Symbol* vsym, Bytebuffer* code, f77skip(); } else { /* rank > 0 && typecode != NC_CHAR*/ char* dimstring; - int index = listlength(f77procs); + size_t index = listlength(f77procs); Bytebuffer* proctext; Bytebuffer* save; List* calllist; diff --git a/ncgen/genj.c b/ncgen/genj.c index e74e0b8fc6..f76a5cb466 100644 --- a/ncgen/genj.c +++ b/ncgen/genj.c @@ -42,13 +42,12 @@ genjava_netcdf(void) { size_t idim, ivar, iatt; int maxdims; - int ndims, nvars, natts, ngatts; const char *filename = rootgroup->file.filename; - ndims = listlength(dimdefs); - nvars = listlength(vardefs); - natts = listlength(attdefs); - ngatts = listlength(gattdefs); + size_t ndims = listlength(dimdefs); + size_t nvars = listlength(vardefs); + size_t natts = listlength(attdefs); + size_t ngatts = listlength(gattdefs); /* Construct the main class */ codeline("import java.util.*;"); diff --git a/ncgen/getfill.c b/ncgen/getfill.c index 0fd0659807..e5c06aa127 100644 --- a/ncgen/getfill.c +++ b/ncgen/getfill.c @@ -74,7 +74,7 @@ fill(Symbol* tsym, Datalist* filler) consisting itself of N constants, where N is the number of fields. Non-array fields will be direct, array fields will be sublists. */ - Datalist* cmpdlist = builddatalist(listlength(tsym->subnodes)); /* list of field constants */ + Datalist* cmpdlist = builddatalist((int)listlength(tsym->subnodes)); /* list of field constants */ for(i=0;isubnodes);i++) { NCConstant* fieldinstance = NULL; Symbol* field = (Symbol*)listget(tsym->subnodes,i); @@ -123,7 +123,7 @@ filllist(Symbol* tsym, Datalist* dl) dlappend(dl,con); break; case NC_COMPOUND: - sublist = builddatalist(listlength(tsym->subnodes)); + sublist = builddatalist((int)listlength(tsym->subnodes)); for(size_t i=0;isubnodes);i++) { Symbol* field = (Symbol*)listget(tsym->subnodes,i); filllist(field->typ.basetype,sublist); diff --git a/ncgen/list.h b/ncgen/list.h index 86f85cc262..06b73bc870 100644 --- a/ncgen/list.h +++ b/ncgen/list.h @@ -57,6 +57,6 @@ EXTERNC List* listclone(List*); #define listclear(l) listsetlength((l),0) #define listextend(l,len) listsetalloc((l),(len)+(l->alloc)) #define listcontents(l) ((l)==NULL?NULL:(l)->content) -#define listlength(l) ((l)==NULL?0:(int)(l)->length) +#define listlength(l) ((l)==NULL?0:(l)->length) #endif /*LIST_H*/ diff --git a/ncgen/util.c b/ncgen/util.c index 8ba96d2267..25e1dc7774 100644 --- a/ncgen/util.c +++ b/ncgen/util.c @@ -373,11 +373,10 @@ char* prefixtostring(List* prefix, char* separator) { size_t slen=0; - int plen; size_t i; char* result; if(prefix == NULL) return pooldup(""); - plen = prefixlen(prefix); + size_t plen = prefixlen(prefix); if(plen == 0) { /* root prefix*/ slen=0; /* slen += strlen(separator);*/ @@ -425,7 +424,7 @@ prefixeq(List* x1, List* x2) { Symbol** l1; Symbol** l2; - int len,i; + size_t len,i; if((len=listlength(x1)) != listlength(x2)) return 0; l1=(Symbol**)listcontents(x1); l2=(Symbol**)listcontents(x2); From 0d354152cadc3d25204d69ebc2d351a116a0adb4 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Thu, 14 Mar 2024 16:00:56 +0000 Subject: [PATCH 16/16] Silence some conversion warnings in ncgen generated files --- ncgen/escapes.c | 2 +- ncgen/genlib.h | 2 +- ncgen/ncgen.h | 2 +- ncgen/ncgen.l | 26 ++++++++++++------------- ncgen/ncgen.y | 8 ++++---- ncgen/ncgenl.c | 50 ++++++++++++++++++++++++------------------------- ncgen/ncgeny.c | 14 +++++++------- 7 files changed, 52 insertions(+), 52 deletions(-) diff --git a/ncgen/escapes.c b/ncgen/escapes.c index e2099d9f75..842022537f 100644 --- a/ncgen/escapes.c +++ b/ncgen/escapes.c @@ -604,7 +604,7 @@ unescapeoct(const char* s) int unescape( const char *yytext, /* text to unescape */ - int yyleng, /* length of yytext */ + size_t yyleng, /* length of yytext */ int isident, /* Is this an identifier? */ char** sp /* Return the unescaped version of yytext */ ) diff --git a/ncgen/genlib.h b/ncgen/genlib.h index 6de7d2fbdd..bd5d9c1719 100644 --- a/ncgen/genlib.h +++ b/ncgen/genlib.h @@ -59,7 +59,7 @@ extern void nestedfqn(Symbol* sym); extern void attfqn(Symbol* sym); /* from: escapes.c */ -extern int unescape(const char*, int, int, char**); +extern int unescape(const char*, size_t, int, char**); extern int unescapeoct(const char* s); extern int unescapehex(const char* s); extern char* cescapifychar(char c, int quote); diff --git a/ncgen/ncgen.h b/ncgen/ncgen.h index f7f901671d..7aa285ffd5 100644 --- a/ncgen/ncgen.h +++ b/ncgen/ncgen.h @@ -119,7 +119,7 @@ typedef struct Specialdata { Datalist* _Fillvalue; /* This is a per-type ; points to the _FillValue attribute node */ int _Storage; /* NC_CHUNKED | NC_CONTIGUOUS | NC_COMPACT*/ size_t* _ChunkSizes; /* NULL => defaults*/ - int nchunks; /* |_Chunksize| ; 0 => not specified*/ + size_t nchunks; /* |_Chunksize| ; 0 => not specified*/ int _Fletcher32; /* 1=>fletcher32*/ int _DeflateLevel; /* 0-9 => level*/ int _Shuffle; /* 0 => false, 1 => true*/ diff --git a/ncgen/ncgen.l b/ncgen/ncgen.l index ffc035e90d..6718e5f40c 100644 --- a/ncgen/ncgen.l +++ b/ncgen/ncgen.l @@ -241,13 +241,13 @@ yyerror("string too long, truncated\n"); yytext[MAXTRST-1] = '\0'; } */ - len = unescape((char *)yytext+1,yyleng-2,!ISIDENT,&s); + len = unescape((char *)yytext+1,(size_t)(yyleng-2),!ISIDENT,&s); if(len < 0) { snprintf(errstr, sizeof(errstr),"Illegal character: %s",yytext); yyerror(errstr); } bbClear(lextext); - bbAppendn(lextext,s,len); + bbAppendn(lextext,s,(size_t)len); bbNull(lextext); if(s) efree(s); return lexdebug(TERMSTRING); @@ -257,11 +257,11 @@ yytext[MAXTRST-1] = '\0'; char* p = yytext+2; int len = yyleng - 2; bbClear(lextext); - bbAppendn(lextext,p,len); + bbAppendn(lextext,p,(size_t)len); if((len % 2) == 1) bbAppend(lextext,'0'); bbNull(lextext); /* convert all chars to lower case */ - for(p=bbContents(lextext);(int)*p;p++) *p = tolower(*p); + for(p=bbContents(lextext);*p;p++) *p = (char)tolower((int)*p); return lexdebug(OPAQUESTRING); } @@ -342,7 +342,7 @@ NIL|nil|Nil { {PATH} { bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); yylval.sym = makepath(bbContents(lextext)); return lexdebug(PATH); @@ -351,7 +351,7 @@ NIL|nil|Nil { {SPECIAL} {struct Specialtoken* st; bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); for(st=specials;st->name;st++) { if(strcmp(bbContents(lextext),st->name)==0) {return lexdebug(st->token);} @@ -360,11 +360,11 @@ NIL|nil|Nil { } {DATASETID} { - int c; + char c; char* p; char* q; /* copy the trimmed name */ bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); p = bbContents(lextext); q = p; @@ -378,7 +378,7 @@ NIL|nil|Nil { {ID} { char* id = NULL; size_t len; len = strlen(yytext); - len = unescape(yytext,len,ISIDENT,&id); + len = (size_t)unescape(yytext,len,ISIDENT,&id); if(NCSTREQ(id, FILL_STRING)) { efree(id); return lexdebug(FILLMARKER); @@ -491,7 +491,7 @@ done: return 0; /* convert to an unsigned long long */ uint64_val = 0; while((c=*hex++)) { - unsigned int hexdigit = (c <= '9'?(c-'0'):(c-'a')+0xa); + unsigned int hexdigit = (unsigned int)(c <= '9'?(c-'0'):(c-'a')+0xa); uint64_val = ((uint64_val << 4) | hexdigit); } switch (tag) { @@ -538,7 +538,7 @@ done: return 0; snprintf(errstr, sizeof(errstr),"bad octal character constant: %s",(char*)yytext); yyerror(errstr); } - byte_val = (unsigned int)oct; + byte_val = (signed char)oct; return lexdebug(BYTE_CONST); } \'\\[xX][0-9a-fA-F][0-9a-fA-F]\' { @@ -547,7 +547,7 @@ done: return 0; snprintf(errstr, sizeof(errstr),"bad hex character constant: %s",(char*)yytext); yyerror(errstr); } - byte_val = (unsigned int)hex; + byte_val = (signed char)hex; return lexdebug(BYTE_CONST); } \'\\.\' { @@ -716,7 +716,7 @@ downconvert(unsigned long long uint64, int* tagp, int isneg, int hasU) { nc_type nct = NC_NAT; int tag = *tagp; - int bit63set = (uint64 >> 63); + int bit63set = (int)(uint64 >> 63); long long int64 = *((long long*)&uint64); if(isneg && hasU) { diff --git a/ncgen/ncgen.y b/ncgen/ncgen.y index 3610f3576b..29f0819830 100644 --- a/ncgen/ncgen.y +++ b/ncgen/ncgen.y @@ -374,7 +374,7 @@ opaquedecl: OPAQUE_ '(' INT_CONST ')' typename $5->objectclass=NC_TYPE; $5->subclass=NC_OPAQUE; $5->typ.typecode=NC_OPAQUE; - $5->typ.size=int32_val; + $5->typ.size=(size_t)int32_val; (void)ncaux_class_alignment(NC_OPAQUE,&$5->typ.alignment); } ; @@ -558,7 +558,7 @@ varspec: varident dimspec count = NC_MAX_VAR_DIMS - 1; stacklen = stackbase + count; } - dimset.ndims = count; + dimset.ndims = (int)count; /* extract the actual dimensions*/ if(dimset.ndims > 0) { for(i=0;i 0) { /* extract the actual dimensions*/ for(i=0;iobjectclass = NC_DIM; $$->dim.isconstant = 1; - $$->dim.declsize = int32_val; + $$->dim.declsize = (size_t)int32_val; } ; diff --git a/ncgen/ncgenl.c b/ncgen/ncgenl.c index 860063fed5..b37d9a2c36 100644 --- a/ncgen/ncgenl.c +++ b/ncgen/ncgenl.c @@ -2079,13 +2079,13 @@ yyerror("string too long, truncated\n"); yytext[MAXTRST-1] = '\0'; } */ - len = unescape((char *)yytext+1,yyleng-2,!ISIDENT,&s); + len = unescape((char *)yytext+1,(size_t)(yyleng-2),!ISIDENT,&s); if(len < 0) { - snprintf(errstr,sizeof(errstr),"Illegal character: %s",yytext); + snprintf(errstr, sizeof(errstr),"Illegal character: %s",yytext); yyerror(errstr); } bbClear(lextext); - bbAppendn(lextext,s,len); + bbAppendn(lextext,s,(size_t)len); bbNull(lextext); if(s) efree(s); return lexdebug(TERMSTRING); @@ -2098,11 +2098,11 @@ YY_RULE_SETUP char* p = yytext+2; int len = yyleng - 2; bbClear(lextext); - bbAppendn(lextext,p,len); + bbAppendn(lextext,p,(size_t)len); if((len % 2) == 1) bbAppend(lextext,'0'); bbNull(lextext); /* convert all chars to lower case */ - for(p=bbContents(lextext);(int)*p;p++) *p = tolower(*p); + for(p=bbContents(lextext);*p;p++) *p = (char)tolower((int)*p); return lexdebug(OPAQUESTRING); } YY_BREAK @@ -2304,7 +2304,7 @@ YY_RULE_SETUP #line 343 "ncgen/ncgen.l" { bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); yylval.sym = makepath(bbContents(lextext)); return lexdebug(PATH); @@ -2315,7 +2315,7 @@ YY_RULE_SETUP #line 352 "ncgen/ncgen.l" {struct Specialtoken* st; bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); for(st=specials;st->name;st++) { if(strcmp(bbContents(lextext),st->name)==0) {return lexdebug(st->token);} @@ -2328,11 +2328,11 @@ case 39: YY_RULE_SETUP #line 362 "ncgen/ncgen.l" { - int c; + char c; char* p; char* q; /* copy the trimmed name */ bbClear(lextext); - bbAppendn(lextext,(char*)yytext,yyleng+1); /* include null */ + bbAppendn(lextext,(char*)yytext,(size_t)yyleng+1); /* include null */ bbNull(lextext); p = bbContents(lextext); q = p; @@ -2349,7 +2349,7 @@ YY_RULE_SETUP #line 379 "ncgen/ncgen.l" { char* id = NULL; size_t len; len = strlen(yytext); - len = unescape(yytext,len,ISIDENT,&id); + len = (size_t)unescape(yytext,len,ISIDENT,&id); if(NCSTREQ(id, FILL_STRING)) { efree(id); return lexdebug(FILLMARKER); @@ -2385,7 +2385,7 @@ YY_RULE_SETUP /* capture the tag string */ tag = collecttag(pos,&stag); if(tag == NC_NAT) { - snprintf(errstr,sizeof(errstr),"Illegal integer suffix: %s",stag); + snprintf(errstr, sizeof(errstr),"Illegal integer suffix: %s",stag); yyerror(errstr); goto done; } @@ -2407,13 +2407,13 @@ YY_RULE_SETUP radix = 10; if(isneg && hasU) { - snprintf(errstr,sizeof(errstr),"Unsigned integer cannot be signed: %s",ncgtext); + snprintf(errstr, sizeof(errstr),"Unsigned integer cannot be signed: %s",ncgtext); yyerror(errstr); goto done; } uint64_val = parseULL(radix, pos,&fail); if(fail) { - snprintf(errstr,sizeof(errstr),"integer constant out of range: %s",ncgtext); + snprintf(errstr, sizeof(errstr),"integer constant out of range: %s",ncgtext); yyerror(errstr); goto done; } @@ -2427,7 +2427,7 @@ YY_RULE_SETUP case NC_FORMAT_64BIT_OFFSET: case NC_FORMAT_NETCDF4_CLASSIC: if(nct > NC_INT) { - snprintf(errstr,sizeof(errstr),"Illegal integer constant for classic format: %s",ncgtext); + snprintf(errstr, sizeof(errstr),"Illegal integer constant for classic format: %s",ncgtext); yyerror(errstr); goto done; } @@ -2456,7 +2456,7 @@ YY_RULE_SETUP /* capture the tag string */ tag = collecttag(yytext,&stag); if(tag == NC_NAT) { - snprintf(errstr,sizeof(errstr),"Illegal integer suffix: %s",stag); + snprintf(errstr, sizeof(errstr),"Illegal integer suffix: %s",stag); yyerror(errstr); //goto done; return 0; @@ -2468,7 +2468,7 @@ YY_RULE_SETUP /* convert to an unsigned long long */ uint64_val = 0; while((c=*hex++)) { - unsigned int hexdigit = (c <= '9'?(c-'0'):(c-'a')+0xa); + unsigned int hexdigit = (unsigned int)(c <= '9'?(c-'0'):(c-'a')+0xa); uint64_val = ((uint64_val << 4) | hexdigit); } switch (tag) { @@ -2484,7 +2484,7 @@ YY_RULE_SETUP break; default: /* should never happen */ if (sscanf((char*)yytext, "%i", &uint32_val) != 1) { - snprintf(errstr,sizeof(errstr),"bad unsigned int constant: %s",(char*)yytext); + snprintf(errstr, sizeof(errstr),"bad unsigned int constant: %s",(char*)yytext); yyerror(errstr); } token = UINT_CONST; @@ -2497,7 +2497,7 @@ YY_RULE_SETUP #line 517 "ncgen/ncgen.l" { if (sscanf((char*)yytext, "%le", &double_val) != 1) { - snprintf(errstr,sizeof(errstr),"bad long or double constant: %s",(char*)yytext); + snprintf(errstr, sizeof(errstr),"bad long or double constant: %s",(char*)yytext); yyerror(errstr); } return lexdebug(DOUBLE_CONST); @@ -2508,7 +2508,7 @@ YY_RULE_SETUP #line 524 "ncgen/ncgen.l" { if (sscanf((char*)yytext, "%e", &float_val) != 1) { - snprintf(errstr,sizeof(errstr),"bad float constant: %s",(char*)yytext); + snprintf(errstr, sizeof(errstr),"bad float constant: %s",(char*)yytext); yyerror(errstr); } return lexdebug(FLOAT_CONST); @@ -2529,10 +2529,10 @@ YY_RULE_SETUP { int oct = unescapeoct(&yytext[2]); if(oct < 0) { - snprintf(errstr,sizeof(errstr),"bad octal character constant: %s",(char*)yytext); + snprintf(errstr, sizeof(errstr),"bad octal character constant: %s",(char*)yytext); yyerror(errstr); } - byte_val = (unsigned int)oct; + byte_val = (signed char)oct; return lexdebug(BYTE_CONST); } YY_BREAK @@ -2542,10 +2542,10 @@ YY_RULE_SETUP { int hex = unescapehex(&yytext[3]); if(byte_val < 0) { - snprintf(errstr,sizeof(errstr),"bad hex character constant: %s",(char*)yytext); + snprintf(errstr, sizeof(errstr),"bad hex character constant: %s",(char*)yytext); yyerror(errstr); } - byte_val = (unsigned int)hex; + byte_val = (signed char)hex; return lexdebug(BYTE_CONST); } YY_BREAK @@ -3681,7 +3681,7 @@ makepath(char* text0) refsym = lookupingroup(NC_GRP,ident,container); if(!lastident) { if(refsym == NULL) { - snprintf(errstr,sizeof(errstr),"Undefined or forward referenced group: %s",ident); + snprintf(errstr, sizeof(errstr),"Undefined or forward referenced group: %s",ident); yyerror(errstr); refsym = rootgroup; } else @@ -3750,7 +3750,7 @@ downconvert(unsigned long long uint64, int* tagp, int isneg, int hasU) { nc_type nct = NC_NAT; int tag = *tagp; - int bit63set = (uint64 >> 63); + int bit63set = (int)(uint64 >> 63); long long int64 = *((long long*)&uint64); if(isneg && hasU) { diff --git a/ncgen/ncgeny.c b/ncgen/ncgeny.c index bd6afd22cd..61a36e336e 100644 --- a/ncgen/ncgeny.c +++ b/ncgen/ncgeny.c @@ -1543,7 +1543,7 @@ yysyntax_error (YYPTRDIFF_T *yymsg_alloc, char **yymsg, return -1; } - /* Avoid snprintf, as that infringes on the user's name space. + /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ { @@ -1985,7 +1985,7 @@ yyparse (void) (yyvsp[0].sym)->objectclass=NC_TYPE; (yyvsp[0].sym)->subclass=NC_OPAQUE; (yyvsp[0].sym)->typ.typecode=NC_OPAQUE; - (yyvsp[0].sym)->typ.size=int32_val; + (yyvsp[0].sym)->typ.size=(size_t)int32_val; (void)ncaux_class_alignment(NC_OPAQUE,&(yyvsp[0].sym)->typ.alignment); } #line 1992 "ncgeny.c" @@ -2279,7 +2279,7 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); count = NC_MAX_VAR_DIMS - 1; stacklen = stackbase + count; } - dimset.ndims = count; + dimset.ndims = (int)count; /* extract the actual dimensions*/ if(dimset.ndims > 0) { for(i=0;iname); count = NC_MAX_VAR_DIMS - 1; stacklen = stackbase + count; } - dimset.ndims = count; + dimset.ndims = (int)count; if(count > 0) { /* extract the actual dimensions*/ for(i=0;iname); { /* Anonymous integer dimension. Can only occur in type definitions*/ char anon[32]; - snprintf(anon,sizeof(anon),"const%u",uint32_val); + snprintf(anon, sizeof(anon),"const%u",uint32_val); (yyval.sym) = install(anon); (yyval.sym)->objectclass = NC_DIM; (yyval.sym)->dim.isconstant = 1; @@ -2427,11 +2427,11 @@ fprintf(stderr,"dimension: %s = UNLIMITED\n",(yyvsp[-2].sym)->name); derror("field dimension must be positive"); YYABORT; } - snprintf(anon,sizeof(anon),"const%d",int32_val); + snprintf(anon, sizeof(anon),"const%d",int32_val); (yyval.sym) = install(anon); (yyval.sym)->objectclass = NC_DIM; (yyval.sym)->dim.isconstant = 1; - (yyval.sym)->dim.declsize = int32_val; + (yyval.sym)->dim.declsize = (size_t)int32_val; } #line 2437 "ncgeny.c" break;