Fix some sign conversion warnings in ncgen

This commit is contained in:
Peter Hill 2023-12-01 09:24:33 +00:00
parent c244ed6683
commit c1977cacc9
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
11 changed files with 49 additions and 57 deletions

View File

@ -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;i<dl->length;i++)
for(size_t i=pos+1;i<dl->length;i++)
dl->data[i-1] = dl->data[i];
dl->length--;
return con;

View File

@ -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 <stddef.h>
#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;i<count;i++,dpl++) {
NCConstant* dp = *dpl;
switch (dp->nctype) {

View File

@ -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) {

View File

@ -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;

View File

@ -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];

View File

@ -5,6 +5,7 @@
*********************************************************************/
#include "includes.h"
#include <stddef.h>
#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<listlength(calllist);i++) {
for(size_t i=0;i<listlength(calllist);i++) {
char* callstmt = (char*)listget(calllist,i);
codeline(callstmt);
}
@ -361,9 +361,8 @@ genf77_netcdf(void)
/* Generate the write procedures */
if(listlength(f77procs) > 0) {
int i;
f77skip();
for(i=0;i<listlength(f77procs);i++) {
for(size_t i=0;i<listlength(f77procs);i++) {
Bytebuffer* proctext = (Bytebuffer*)listget(f77procs,i);
codedump(proctext);
bbFree(proctext);
@ -512,10 +511,10 @@ f77fold(Bytebuffer* lines)
int incr = F77_MAX_STMT;
/* Check to ensure we are folding at a legal point */
if(*(line0+(incr-1)) == '\\') incr--;
bbAppendn(lines,line0,incr);
bbAppendn(lines,line0,(size_t)incr);
bbCat(lines,"\n 1"); /* comment extender */
line0 += incr;
linelen -= incr;
linelen -= (size_t)incr;
}
/* Do last part of the line */
bbAppendn(lines,line0,linelen);

View File

@ -5,6 +5,7 @@
*********************************************************************/
#include "includes.h"
#include <stddef.h>
#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;

View File

@ -6,6 +6,7 @@
#include "includes.h"
#include "dump.h"
#include <stddef.h>
/* 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;i<listlength(tsym->subnodes);i++) {
for(size_t i=0;i<listlength(tsym->subnodes);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));

View File

@ -10,6 +10,7 @@
#include "ncoffsets.h"
#include "netcdf_aux.h"
#include "ncpathmgr.h"
#include <stddef.h>
#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;i<listlength(symlist);i++) {
for(size_t i=0;i<listlength(symlist);i++) {
Symbol* sym = listget(symlist,i);
if(sym->typ.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;i<listlength(container->subnodes);i++) {
for(size_t i=0;i<listlength(container->subnodes);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;i<listlength(enumt->subnodes);i++) {
for(size_t i=0;i<listlength(enumt->subnodes);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;i<listlength(typdefs);i++) {
for(size_t i=0;i<listlength(typdefs);i++) {
Symbol* sym = (Symbol*)listget(typdefs,i);
ASSERT(sym->objectclass == 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;i<listlength(tsym->subnodes);i++) {
for(size_t i=0;i<listlength(tsym->subnodes);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;i<listlength(tsym->subnodes);i++) {
size_t offset = 0;
size_t largealign = 1;
for(size_t i=0;i<listlength(tsym->subnodes);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;i<listlength(vardefs);i++) {
for(size_t i=0;i<listlength(vardefs);i++) {
Symbol* vsym = (Symbol*)listget(vardefs,i);
Symbol* basetype = vsym->typ.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;j<vsym->typ.dimset.ndims;j++) {
for(size_t j=0;j<vsym->typ.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;i<listlength(typdefs);i++) {
Symbol* tsym = (Symbol*)listget(typdefs,i);
@ -713,7 +706,7 @@ processtypesizes(void)
static void
processattributes(void)
{
int i,j;
size_t i,j;
/* process global attributes*/
for(i=0;i<listlength(gattdefs);i++) {
Symbol* asym = (Symbol*)listget(gattdefs,i);
@ -967,11 +960,10 @@ lookupgroup(List* prefix)
Symbol*
lookupingroup(nc_class objectclass, char* name, Symbol* grp)
{
int i;
if(name == NULL) return NULL;
if(grp == NULL) grp = rootgroup;
dumpgroup(grp);
for(i=0;i<listlength(grp->subnodes);i++) {
for(size_t i=0;i<listlength(grp->subnodes);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;i<listlength(seq);i++) {
for(size_t i=0;i<listlength(seq);i++) {
Symbol* sub = (Symbol*)listget(seq,i);
if(sub == sym) return 1;
}
@ -1032,7 +1023,7 @@ sqContains(List* seq, Symbol* sym)
static void
checkconsistency(void)
{
int i;
size_t i;
for(i=0;i<listlength(grpdefs);i++) {
Symbol* sym = (Symbol*)listget(grpdefs,i);
if(sym == rootgroup) {
@ -1150,7 +1141,7 @@ thisunlim->name,
static void
processunlimiteddims(void)
{
int i;
size_t i;
/* Set all unlimited dims to size 0; */
for(i=0;i<listlength(dimdefs);i++) {
Symbol* dim = (Symbol*)listget(dimdefs,i);
@ -1310,8 +1301,7 @@ done:
static void
processvardata(void)
{
int i;
for(i=0;i<listlength(vardefs);i++) {
for(size_t i=0;i<listlength(vardefs);i++) {
Symbol* vsym = (Symbol*)listget(vardefs,i);
NCConstant* con;
if(vsym->data == NULL) continue;

View File

@ -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)

View File

@ -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 <stddef.h>
#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);