Silence many conversion warnings in libdap2

This commit is contained in:
Peter Hill 2024-03-13 16:51:24 +00:00
parent 41f17fad2d
commit 962da2d140
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
13 changed files with 77 additions and 86 deletions

View File

@ -39,14 +39,15 @@ iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
cache = nccomm->cdf.cache;
cachenode = cache->prefetch;
if(cachenode!= NULL) {
for(found=0,i=0;i<nclistlength(cachenode->vars);i++) {
found=0;
for(size_t i=0;i<nclistlength(cachenode->vars);i++) {
CDFnode* var = (CDFnode*)nclistget(cachenode->vars,i);
if(var == target) {
if(var == target) {
if(cachenodep) *cachenodep = cachenode;
found=1;
goto done;
}
}
found=1;
goto done;
}
}
}
/*search other cache nodes starting at latest first */

View File

@ -17,7 +17,7 @@ static NCerror sequencecheckr(CDFnode* node, NClist* vars, CDFnode* topseq);
static NCerror restructr(NCDAPCOMMON*, CDFnode*, CDFnode*, NClist*);
static NCerror repairgrids(NCDAPCOMMON*, NClist*);
static NCerror structwrap(NCDAPCOMMON*, CDFnode*, CDFnode*, size_t, CDFnode*);
static int findin(CDFnode* parent, CDFnode* child);
static size_t findin(CDFnode* parent, CDFnode* child);
static CDFnode* makenewstruct(NCDAPCOMMON*, CDFnode*, CDFnode*);
static NCerror mapnodesr(CDFnode*, CDFnode*, int depth);
static NCerror mapfcn(CDFnode* dstnode, CDFnode* srcnode);
@ -135,10 +135,10 @@ fprintf(stderr,"computevarnodes: var: %s\n",makecdfpathstring(node,"."));
NCerror
fixgrid(NCDAPCOMMON* nccomm, CDFnode* grid)
{
unsigned int i,glen;
unsigned int i;
CDFnode* array;
glen = nclistlength(grid->subnodes);
size_t glen = nclistlength(grid->subnodes);
array = (CDFnode*)nclistget(grid->subnodes,0);
if(nccomm->controls.flags & (NCF_NC3)) {
/* Rename grid Array: variable, but leave its oc base name alone */
@ -507,7 +507,7 @@ repairgrids(NCDAPCOMMON* ncc, NClist* repairlist)
for(i=0;i<nclistlength(repairlist);i+=2) {
CDFnode* node = (CDFnode*)nclistget(repairlist,i);
CDFnode* pattern = (CDFnode*)nclistget(repairlist,i+1);
int index = findin(node->container,node);
size_t index = findin(node->container,node);
ncstat = structwrap(ncc, node,node->container,index,
pattern->container);
#ifdef DEBUG
@ -538,12 +538,11 @@ structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, size_t parentindex,
return NC_NOERR;
}
static int
static size_t
findin(CDFnode* parent, CDFnode* child)
{
size_t i;
NClist* subnodes = parent->subnodes;
for(i=0;i<nclistlength(subnodes);i++) {
for(size_t i=0;i<nclistlength(subnodes);i++) {
if(nclistget(subnodes,i) == child)
return i;
}

View File

@ -341,8 +341,8 @@ matchsuffix(NClist* matchpath, NClist* segments)
{
size_t i;
int pathstart;
int nsegs = nclistlength(segments);
int pathlen = nclistlength(matchpath);
int nsegs = (int)nclistlength(segments);
int pathlen = (int)nclistlength(matchpath);
int segmatch;
/* try to match the segment list as a suffix of the path list */
@ -360,12 +360,12 @@ matchsuffix(NClist* matchpath, NClist* segments)
for(i=0;i<nsegs;i++) {
CDFnode* node = (CDFnode*)nclistget(matchpath, (size_t)pathstart+i);
DCEsegment* seg = (DCEsegment*)nclistget(segments,i);
int rank = seg->rank;
size_t rank = seg->rank;
segmatch = 1; /* until proven otherwise */
/* Do the names match (in oc name space) */
if(strcmp(seg->name,node->ocname) != 0) {
segmatch = 0;
} else {
} else if (rank != 0) {
/* Do the ranks match (watch out for sequences) */
if(node->nctype == NC_Sequence)
rank--; /* remove sequence pseudo-rank */

View File

@ -295,9 +295,8 @@ dapcvtattrval(nc_type etype, void* dst, NClist* src, NCattribute* att)
}
} else if(etype == NC_CHAR) {
char* p = (char*)dstmem;
size_t count;
int nread;
count = sscanf(s,"%c%n",p,&nread);
int count = sscanf(s,"%c%n",p,&nread);
if(count != 1 || nread != slen)
{ncstat = NC_EBADTYPE; goto next;}
} else if(etype == NC_STRING || etype == NC_URL) {
@ -326,9 +325,8 @@ cvtnumconst(const char* s, struct Value* val)
{
size_t slen = strlen(s);
int nread; /* # of chars read */
size_t count; /* # of conversions */
/* Try to convert to integer first */
count = sscanf(s,"%lld%n",&val->llval,&nread);
int count = sscanf(s,"%lld%n",&val->llval,&nread);
if(count == 1 && nread == slen)
return NC_INT;
/* Try to convert to float second */

View File

@ -22,7 +22,7 @@ static void dumptreer(CDFnode* root, NCbytes* buf, int indent, int visible);
int
dumpmetadata(int ncid, NChdr** hdrp)
{
int stat,i,j,k;
int stat,i,j;
NChdr* hdr = (NChdr*)calloc(1,sizeof(NChdr));
MEMCHECK(hdr,NC_ENOMEM);
hdr->ncid = ncid;
@ -74,7 +74,7 @@ dumpmetadata(int ncid, NChdr** hdrp)
MEMCHECK(values,NC_ENOMEM);
stat = nc_get_att(hdr->ncid,NC_GLOBAL,att->name,values);
CHECK(stat);
for(k=0;k<nvalues;k++) {
for(size_t k=0;k<nvalues;k++) {
fprintf(stdout," ");
dumpdata1(octypetonc(att->etype),k,values);
}
@ -141,7 +141,7 @@ dumpmetadata(int ncid, NChdr** hdrp)
CHECK(stat);
fprintf(stdout,"\tattr[%d]: name=%s type=%s values(%lu)=",
j,att->name,nctypetostring(octypetonc(att->etype)),(unsigned long)nvalues);
for(k=0;k<nvalues;k++) {
for(size_t k=0;k<nvalues;k++) {
fprintf(stdout," ");
dumpdata1(octypetonc(att->etype),k,values);
}

View File

@ -13,7 +13,6 @@
Dapodometer*
dapodom_fromsegment(DCEsegment* segment, size_t startindex, size_t stopindex)
{
int i;
Dapodometer* odom;
assert(stopindex > startindex);
@ -21,7 +20,7 @@ dapodom_fromsegment(DCEsegment* segment, size_t startindex, size_t stopindex)
odom = (Dapodometer*)calloc(1,sizeof(Dapodometer));
MEMCHECK(odom,NULL);
odom->rank = (stopindex - startindex);
for(i=0;i<odom->rank;i++) {
for(size_t i=0;i<odom->rank;i++) {
odom->start[i] = segment->slices[i+startindex].first;
odom->stride[i] = segment->slices[i+startindex].stride;
odom->stop[i] = (segment->slices[i+startindex].last + 1);
@ -49,10 +48,9 @@ dapodom_new(size_t rank,
assert(odom->rank <= NC_MAX_VAR_DIMS);
for(i=0;i<odom->rank;i++) {
size_t istart,icount,istop,ideclsize;
ptrdiff_t istride;
istart = (start != NULL ? start[i] : 0);
icount = (count != NULL ? count[i] : (size != NULL ? size[i] : 1));
istride = (size_t)(stride != NULL ? stride[i] : 1);
size_t istride = (size_t)(stride != NULL ? stride[i] : 1);
istop = istart + icount*istride;
ideclsize = (size != NULL ? size[i]: (istop - istart));
odom->start[i] = istart;
@ -99,14 +97,13 @@ dapodom_more(Dapodometer* odom)
}
/* Convert current dapodometer settings to a single integer count*/
off_t
size_t
dapodom_count(Dapodometer* odom)
{
int i;
off_t offset = 0;
for(i=0;i<odom->rank;i++) {
offset *= odom->declsize[i];
offset += odom->index[i];
size_t offset = 0;
for(size_t i=0;i<odom->rank;i++) {
offset *= odom->declsize[i];
offset += odom->index[i];
}
return offset;
}
@ -136,7 +133,7 @@ dapodom_varmcount(Dapodometer* odom, const ptrdiff_t* steps, const size_t* decls
tmp = odom->index[i];
tmp = tmp - odom->start[i];
tmp = tmp / odom->stride[i];
tmp = tmp * steps[i];
tmp = tmp * (size_t)steps[i];
offset += tmp;
}
return offset;

View File

@ -6,8 +6,10 @@
#ifndef DAPODOM_H
#define DAPODOM_H 1
#include <stddef.h>
typedef struct Dapodometer {
int rank;
size_t rank;
size_t index[NC_MAX_VAR_DIMS];
size_t start[NC_MAX_VAR_DIMS];
#if 0
@ -31,7 +33,7 @@ extern void dapodom_free(Dapodometer*);
extern int dapodom_more(Dapodometer* odom);
extern int dapodom_next(Dapodometer* odo);
extern off_t dapodom_count(Dapodometer* odo);
extern size_t dapodom_count(Dapodometer* odo);
extern size_t dapodom_varmcount(Dapodometer*, const ptrdiff_t*, const size_t*);

View File

@ -21,7 +21,7 @@ extern int oc_dumpnode(OClink, OCddsnode);
static char* repairname(const char* name, const char* badchars);
static int nccpadding(unsigned long offset, int alignment);
static size_t nccpadding(unsigned long offset, size_t alignment);
/**************************************************/
@ -180,11 +180,10 @@ nctypetostring(nc_type nctype)
int
dapalignbuffer(NCbytes* buf, int alignment)
{
int pad;
unsigned long len;
if(buf == NULL) return 0;
len = ncbyteslength(buf);
pad = nccpadding(len,alignment);
size_t pad = nccpadding(len, (size_t)alignment);
#ifdef TEST
for(;pad > 0;pad--)
@ -269,9 +268,8 @@ int
nclistdeleteall(NClist* l, void* elem)
{
int i; /* do not make unsigned */
unsigned int len,found;
found = 0;
len = nclistlength(l);
size_t len = nclistlength(l);
int found = 0;
for(i=len-1;i>=0;i--) {
void* test = nclistget(l,i);
if(test==elem) {
@ -764,7 +762,7 @@ repairname(const char* name, const char* badchars)
char* newname;
const char *p;
char *q;
int c;
char c;
size_t nnlen = 0;
if(name == NULL) return NULL;
@ -804,12 +802,11 @@ dap_getselection(NCURI* uri)
}
/* Compute padding */
static int
nccpadding(unsigned long offset, int alignment)
static size_t
nccpadding(unsigned long offset, size_t alignment)
{
int pad,rem;
rem = (alignment==0?0:(offset % alignment));
pad = (rem==0?0:(alignment - rem));
size_t rem = (alignment==0?0:(offset % alignment));
size_t pad = (rem==0?0:(alignment - rem));
return pad;
}

View File

@ -601,7 +601,7 @@ dcedump(DCEnode* node, NCbytes* buf)
case CES_SEGMENT: {
DCEsegment* segment = (DCEsegment*)node;
char* name = (segment->name?segment->name:"<unknown>");
int rank = segment->rank;
size_t rank = segment->rank;
int i;
name = nulldup(name);
ncbytescat(buf,name);
@ -955,7 +955,7 @@ dcesegment_transpose(DCEsegment* segment,
size_t
dcesegmentsize(DCEsegment* seg, size_t start, size_t stop)
{
int i, count;
size_t i, count;
if(!seg->slicesdefined) return 0; /* actually, we don't know */
for(count=1,i=start;i<stop;i++) {
count *= seg->slices[i].count;
@ -1036,7 +1036,7 @@ dcedumpraw(DCEnode* node, NCbytes* buf)
case CES_SEGMENT: {
DCEsegment* segment = (DCEsegment*)node;
int rank = segment->rank;
size_t rank = segment->rank;
char* name = (segment->name?segment->name:"<unknown>");
ncbytescat(buf," name=");
ncbytescat(buf,name);

View File

@ -41,7 +41,6 @@ dcelex(YYSTYPE* lvalp, DCEparsestate* state)
DCElexstate* lexstate = state->lexstate;
int token;
int c;
int len;
char* p=NULL;
token = 0;
ncbytesclear(lexstate->yytext);
@ -75,7 +74,7 @@ dcelex(YYSTYPE* lvalp, DCEparsestate* state)
if(d2 < 0) {
dceerror(state,"Illegal \\xDD in SCAN_STRING");
} else {
c=(((unsigned int)d1)<<4) | (unsigned int)d2;
c=(int)((((unsigned int)d1)<<4) | (unsigned int)d2);
}
}
} break;
@ -138,7 +137,7 @@ dcelex(YYSTYPE* lvalp, DCEparsestate* state)
}
}
lexstate->next = p;
len = ncbyteslength(lexstate->yytext);
size_t len = ncbyteslength(lexstate->yytext);
if(len > MAX_TOKEN_LENGTH) len = MAX_TOKEN_LENGTH;
strncpy(lexstate->lasttokentext,ncbytescontents(lexstate->yytext),len);
lexstate->lasttokentext[len] = '\0';

View File

@ -211,10 +211,10 @@ array_indices(DCEparsestate* state, Object list0, Object indexno)
start = 1;
}
slice = (DCEslice*)dcecreate(CES_SLICE);
slice->first = start;
slice->first = (size_t)start;
slice->stride = 1;
slice->length = 1;
slice->last = start;
slice->last = (size_t)start;
slice->count = 1;
nclistpush(list,(void*)slice);
return list;

View File

@ -23,11 +23,11 @@ struct NCMEMORY {
/* Forward:*/
static NCerror moveto(NCDAPCOMMON*, Getvara*, CDFnode* dataroot, void* memory);
static NCerror movetor(NCDAPCOMMON*, OCdatanode currentcontent,
NClist* path, int depth,
NClist* path, size_t depth,
Getvara*, size_t dimindex,
struct NCMEMORY*, NClist* segments);
static NCerror movetofield(NCDAPCOMMON*, OCdatanode,
NClist*, int depth,
NClist*, size_t depth,
Getvara*, size_t dimindex,
struct NCMEMORY*, NClist* segments);
@ -195,7 +195,7 @@ fprintf(stderr,"\n");
goto fail;
}
if(startp[i] >= dim->dim.declsize
|| startp[i]+(stridep[i]*(countp[i]-1)) >= dim->dim.declsize) {
|| startp[i]+((size_t)stridep[i]*(countp[i]-1)) >= dim->dim.declsize) {
ncstat = NC_EINVALCOORDS;
goto fail;
}
@ -479,7 +479,7 @@ static NCerror
movetor(NCDAPCOMMON* nccomm,
OCdatanode currentcontent,
NClist* path,
int depth, /* depth is position in segment list*/
size_t depth, /* depth is position in segment list*/
Getvara* xgetvar,
size_t dimindex, /* dimindex is position in xgetvar->slices*/
struct NCMEMORY* memory,
@ -596,10 +596,10 @@ fprintf(stderr," segment=%s hasstringdim=%d\n",
case NC_Atomic:
if(hasstringdim)
ncstat = extractstring(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
else
ncstat = extract(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
break;
ncstat = extractstring(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
else
ncstat = extract(nccomm, xgetvar, xnode, segment, dimindex, conn, currentcontent, memory);
break;
}
@ -615,7 +615,7 @@ static NCerror
movetofield(NCDAPCOMMON* nccomm,
OCdatanode currentcontent,
NClist* path,
int depth, /* depth is position in segment list*/
size_t depth, /* depth is position in segment list*/
Getvara* xgetvar,
size_t dimindex, /* dimindex is position in xgetvar->slices*/
struct NCMEMORY* memory,
@ -628,7 +628,7 @@ movetofield(NCDAPCOMMON* nccomm,
CDFnode* xnode = (CDFnode*)nclistget(path,depth);
OCdatanode fieldcontent = NULL;
CDFnode* xnext;
int newdepth;
size_t newdepth;
int ffield;
/* currentcontent points to the grid/dataset/structure/record instance */
@ -806,8 +806,8 @@ fprintf(stderr,"\n");
=> we have to use odometer on leading prefix.
If conversion required, then read one-by-one
*/
int safeindex = dcesafeindex(segment,0,rank0);
assert(safeindex >= 0 && safeindex <= rank0);
size_t safeindex = dcesafeindex(segment,0,rank0);
assert(safeindex <= rank0);
if(!requireconversion && safeindex == 0) { /* can read whole thing */
size_t internlen;
@ -883,7 +883,6 @@ static NCerror
slicestring(OClink conn, char* stringmem, DCEslice* slice, struct NCMEMORY* memory)
{
size_t stringlen;
unsigned int i;
NCerror ncstat = NC_NOERR;
char* lastchar;
size_t charcount; /* number of characters inserted into memory */
@ -903,7 +902,7 @@ slice->first,slice->stride,slice->last,slice->declsize);
/* Stride across string; if we go past end of string, then pad*/
charcount = 0;
for(i=slice->first;i<slice->length;i+=slice->stride) {
for(size_t i=slice->first;i<slice->length;i+=slice->stride) {
if(i < stringlen)
*memory->next = stringmem[i];
else /* i >= stringlen*/

View File

@ -645,7 +645,6 @@ done:
static NCerror
builddims(NCDAPCOMMON* dapcomm)
{
int i;
NCerror ncstat = NC_NOERR;
int dimid;
NClist* dimset = NULL;
@ -657,12 +656,13 @@ builddims(NCDAPCOMMON* dapcomm)
/* Sort by fullname just for the fun of it */
for(;;) {
int last = nclistlength(dimset) - 1;
const size_t last = nclistlength(dimset);
if (last == 0) break;
int swap = 0;
for(i=0;i<last;i++) {
for(size_t i=0;i<last-1;i++) {
CDFnode* dim1 = (CDFnode*)nclistget(dimset,i);
CDFnode* dim2 = (CDFnode*)nclistget(dimset,i+1);
if(strcmp(dim1->ncfullname,dim2->ncfullname) > 0) {
if(strcmp(dim1->ncfullname,dim2->ncfullname) > 0) {
nclistset(dimset,i,(void*)dim2);
nclistset(dimset,i+1,(void*)dim1);
swap = 1;
@ -695,7 +695,7 @@ builddims(NCDAPCOMMON* dapcomm)
}
for(i=0;i<nclistlength(dimset);i++) {
for(size_t i=0;i<nclistlength(dimset);i++) {
CDFnode* dim = (CDFnode*)nclistget(dimset,i);
if(dim->dim.basedim != NULL) continue; /* handle below */
if(DIMFLAG(dim,CDFDIMRECORD)) continue; /* defined above */
@ -713,7 +713,7 @@ fprintf(stderr,"define: dim: %s=%ld\n",dim->ncfullname,(long)dim->dim.declsize);
/* Make all duplicate dims have same dimid as basedim*/
/* (see computecdfdimnames)*/
for(i=0;i<nclistlength(dimset);i++) {
for(size_t i=0;i<nclistlength(dimset);i++) {
CDFnode* dim = (CDFnode*)nclistget(dimset,i);
if(dim->dim.basedim != NULL) {
dim->ncid = dim->dim.basedim->ncid;
@ -1242,9 +1242,9 @@ static NCerror
applyclientparams(NCDAPCOMMON* nccomm)
{
size_t i;
int len;
int dfaltstrlen = DEFAULTSTRINGLENGTH;
int dfaltseqlim = DEFAULTSEQLIMIT;
unsigned int len;
unsigned int dfaltstrlen = DEFAULTSTRINGLENGTH;
unsigned int dfaltseqlim = DEFAULTSEQLIMIT;
const char* value;
char tmpname[NC_MAX_NAME+32];
char* pathstr = NULL;
@ -1287,7 +1287,7 @@ applyclientparams(NCDAPCOMMON* nccomm)
dfaltseqlim = 0;
value = paramlookup(nccomm,"limit");
if(value != NULL && strlen(value) != 0) {
if(sscanf(value,"%d",&len) && len > 0) dfaltseqlim = len;
if(sscanf(value,"%u",&len) && len > 0) dfaltseqlim = len;
}
nccomm->cdf.defaultsequencelimit = dfaltseqlim;
@ -1296,7 +1296,7 @@ applyclientparams(NCDAPCOMMON* nccomm)
if(value == NULL)
value = paramlookup(nccomm,"maxstrlen");
if(value != NULL && strlen(value) != 0) {
if(sscanf(value,"%d",&len) && len > 0) dfaltstrlen = len;
if(sscanf(value,"%u",&len) && len > 0) dfaltstrlen = len;
}
nccomm->cdf.defaultstringlength = dfaltstrlen;
@ -1720,7 +1720,6 @@ countsequence(NCDAPCOMMON* dapcomm, CDFnode* xseq, size_t* sizep)
{
unsigned int i;
NClist* path = nclistnew();
int index;
OCerror ocstat = OC_NOERR;
NCerror ncstat = NC_NOERR;
OClink conn = dapcomm->oc.conn;
@ -1761,7 +1760,7 @@ countsequence(NCDAPCOMMON* dapcomm, CDFnode* xseq, size_t* sizep)
}
/* get next node in path; structure/dataset => exists */
next = (CDFnode*)nclistget(path,i+1);
index = fieldindex(current,next);
size_t index = fieldindex(current,next);
/* Move to appropriate field */
ocstat = oc_data_ithfield(conn,data,index,&nextdata);
if(ocstat) goto done;
@ -2146,7 +2145,7 @@ fail:
static NCerror
suppressunusablevars(NCDAPCOMMON* dapcomm)
{
int i,j;
int i;
int found = 1;
NClist* path = nclistnew();
@ -2158,7 +2157,7 @@ suppressunusablevars(NCDAPCOMMON* dapcomm)
/* See if this var is under an unusable sequence */
nclistclear(path);
collectnodepath(var,path,WITHOUTDATASET);
for(j=0;j<nclistlength(path);j++) {
for(size_t j=0;j<nclistlength(path);j++) {
CDFnode* node = (CDFnode*)nclistget(path,j);
if(node->nctype == NC_Sequence
&& !node->usesequence) {