Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix most warnings in libdap2 #2887

Merged
merged 8 commits into from
Jul 15, 2024
10 changes: 5 additions & 5 deletions libdap2/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ iscached(NCDAPCOMMON* nccomm, CDFnode* target, NCcachenode** cachenodep)
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 */
Expand Down
22 changes: 10 additions & 12 deletions libdap2/cdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ extern char* ocfqn(OCddsnode);
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*, int, CDFnode*, int);
static int findin(CDFnode* parent, CDFnode* child);
static NCerror structwrap(NCDAPCOMMON*, CDFnode*, CDFnode*, size_t, CDFnode*);
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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -507,10 +507,9 @@ 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);
int tindex = findin(pattern->container,pattern);
size_t index = findin(node->container,node);
ncstat = structwrap(ncc, node,node->container,index,
pattern->container,tindex);
pattern->container);
#ifdef DEBUG
fprintf(stderr,"repairgrids: %s -> %s\n",
ocfqn(node->ocnode),ocfqn(pattern->ocnode));
Expand All @@ -521,8 +520,8 @@ ocfqn(node->ocnode),ocfqn(pattern->ocnode));
}

static NCerror
structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, int parentindex,
CDFnode* patterngrid, int gridindex)
structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, size_t parentindex,
CDFnode* patterngrid)
{
CDFnode* newstruct;

Expand All @@ -539,12 +538,11 @@ structwrap(NCDAPCOMMON* ncc, CDFnode* node, CDFnode* parent, int 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;
}
Expand Down
11 changes: 4 additions & 7 deletions libdap2/constraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,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 */
Expand All @@ -359,12 +359,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 */
Expand Down Expand Up @@ -698,13 +698,11 @@ dapvar2projection(CDFnode* var, DCEprojection** projectionp)
NClist* path = nclistnew();
NClist* segments;
DCEprojection* projection = NULL;
int dimindex;

/* Collect the nodes needed to construct the projection segments */
collectnodepath(var,path,!WITHDATASET);

segments = nclistnew();
dimindex = 0; /* point to next subset of slices */
nclistsetalloc(segments,nclistlength(path));
for(i=0;i<nclistlength(path);i++) {
DCEsegment* segment = (DCEsegment*)dcecreate(CES_SEGMENT);
Expand All @@ -728,7 +726,6 @@ dapvar2projection(CDFnode* var, DCEprojection** projectionp)
}
segment->slicesdefined = 1;
segment->slicesdeclized = 1;
dimindex += localrank;
nclistpush(segments,(void*)segment);
}

Expand Down
8 changes: 4 additions & 4 deletions libdap2/dapcvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -326,16 +325,17 @@ 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 */
#ifdef _WIN32
if (!_strnicmp(s, "NaN", 3)) {count = 1; nread = 3; val->dval = NAN;} else
#endif
{
count = sscanf(s,"%lg%n",&val->dval,&nread);
}
if(count == 1 && nread == slen)
return NC_DOUBLE;
return NC_INT;
Expand Down
6 changes: 3 additions & 3 deletions libdap2/dapdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
19 changes: 8 additions & 11 deletions libdap2/dapodom.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
Dapodometer*
dapodom_fromsegment(DCEsegment* segment, size_t startindex, size_t stopindex)
{
int i;
Dapodometer* odom;

assert(stopindex > startindex);
assert((stopindex - startindex) <= NC_MAX_VAR_DIMS);
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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -135,7 +132,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;
Expand Down
6 changes: 4 additions & 2 deletions libdap2/dapodom.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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*);

Expand Down
16 changes: 7 additions & 9 deletions libdap2/daputil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**************************************************/

Expand Down Expand Up @@ -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--)
Expand Down Expand Up @@ -760,7 +759,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;
Expand Down Expand Up @@ -800,12 +799,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;
}

Expand Down
6 changes: 3 additions & 3 deletions libdap2/dceconstraints.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions libdap2/dcelex.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions libdap2/dceparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading
Loading