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 all warnings in ncdap4 #2898

Merged
merged 11 commits into from
May 16, 2024
6 changes: 3 additions & 3 deletions include/ncdap.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ affect the operation of the system.
*/

typedef unsigned int NCFLAGS;
# define SETFLAG(controls,flag) (((controls).flags) |= (flag))
# define CLRFLAG(controls,flag) (((controls).flags) &= ~(flag))
# define FLAGSET(controls,flag) (((controls.flags) & (flag)) != 0)
#define SETFLAG(controls,flag) (((controls).flags) |= (NCFLAGS)(flag))
#define CLRFLAG(controls,flag) (((controls).flags) &= ~(NCFLAGS)(flag))
#define FLAGSET(controls,flag) ((((controls).flags) & (NCFLAGS)(flag)) != 0)

/* Defined flags */
#define NCF_NC3 (0x0001) /* DAP->netcdf-3 */
Expand Down
4 changes: 2 additions & 2 deletions libdap4/d4curlfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,8 @@ NCD4_get_rcproperties(NCD4INFO* state)
unsigned long interval=0;
if(sscanf(option,"%lu/%lu",&idle,&interval) != 2)
fprintf(stderr,"Illegal KEEPALIVE VALUE: %s\n",option);
state->curl->keepalive.idle = idle;
state->curl->keepalive.interval = interval;
state->curl->keepalive.idle = (long)idle;
state->curl->keepalive.interval = (long)interval;
state->curl->keepalive.active = 1;
}
}
Expand Down
6 changes: 3 additions & 3 deletions libdap4/d4data.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static unsigned NCD4_computeChecksum(NCD4meta* meta, NCD4node* topvar);
/* Macro define procedures */

#ifdef D4DUMPCSUM
static unsigned int debugcrc32(unsigned int crc, const void *buf, size_t size)
static unsigned int debugcrc32(unsigned int crc, const void *buf, unsigned int size)
{
int i;
fprintf(stderr,"crc32: ");
Expand Down Expand Up @@ -309,7 +309,7 @@ fillopfixed(NCD4meta* meta, d4size_t opaquesize, NCD4offset* offset, void** dstp
SKIPCOUNTER(offset);
/* verify that it is the correct size */
actual = count;
delta = actual - opaquesize;
delta = (int)actual - (int)opaquesize;
if(delta != 0) {
#ifdef FIXEDOPAQUE
nclog(NCLOGWARN,"opaque changed from %lu to %lu",actual,opaquesize);
Expand Down Expand Up @@ -443,7 +443,7 @@ NCD4_computeChecksum(NCD4meta* meta, NCD4node* topvar)
ASSERT((ISTOPLEVEL(topvar)));

#ifndef HYRAXCHECKSUM
csum = CRC32(csum,topvar->data.dap4data.memory,topvar->data.dap4data.size);
csum = CRC32(csum,topvar->data.dap4data.memory, (unsigned int)topvar->data.dap4data.size);
#else
if(topvar->basetype->subsort != NC_STRING) {
csum = CRC32(csum,topvar->data.dap4data.memory,topvar->data.dap4data.size);
Expand Down
2 changes: 1 addition & 1 deletion libdap4/d4file.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ NCD4_open(const char * path, int mode,
{ret = NC_ENOMEM; goto done;}
dmrresp->controller = d4info;

if((ret=NCD4_readDMR(d4info, d4info->controls.flags.flags, d4info->dmruri, dmrresp))) goto done;
if((ret=NCD4_readDMR(d4info, d4info->dmruri, dmrresp))) goto done;

/* set serial.rawdata */
len = ncbyteslength(d4info->curl->packet);
Expand Down
9 changes: 4 additions & 5 deletions libdap4/d4fix.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ static int
delimitAtomicVar(NCD4meta* compiler, NCD4node* var, NCD4offset* offset)
{
int ret = NC_NOERR;
int typesize;
d4size_t i;
d4size_t dimproduct;
nc_type tid;
Expand All @@ -249,7 +248,7 @@ delimitAtomicVar(NCD4meta* compiler, NCD4node* var, NCD4offset* offset)
truetype = basetype->basetype;

tid = truetype->subsort;
typesize = NCD4_typesize(tid);
size_t typesize = NCD4_typesize(tid);
if(tid != NC_STRING) {
INCR(offset,(typesize*dimproduct));
} else if(tid == NC_STRING) { /* walk the counts */
Expand Down Expand Up @@ -448,13 +447,13 @@ skipAtomicInstance(NCD4meta* compiler, NCD4node* type, NCD4offset* offset)
{
int ret = NC_NOERR;
d4size_t count;
int typesize;
size_t typesize;

switch (type->subsort) {
default: /* fixed size atomic type */
typesize = NCD4_typesize(type->meta.id);
INCR(offset,typesize);
break;
INCR(offset,typesize);
break;
case NC_STRING:
/* Get string count */
count = GETCOUNTER(offset);
Expand Down
2 changes: 1 addition & 1 deletion libdap4/d4http.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ NCD4_fetchurl(CURL* curl, const char* url, NCbytes* buf, long* filetime, int* ht
if(cstat != CURLE_OK) goto done;

httpcode = NCD4_fetchhttpcode(curl);
if(httpcodep) *httpcodep = httpcode;
if(httpcodep) *httpcodep = (int)httpcode;

/* Get the last modified time */
if(filetime != NULL)
Expand Down
11 changes: 5 additions & 6 deletions libdap4/d4meta.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int convertString(union ATOMICS* converter, NCD4node* type, const char* s
static void* copyAtomic(union ATOMICS* converter, nc_type type, size_t len, void* dst, NClist* blobs);
static int decodeEconst(NCD4meta* builder, NCD4node* enumtype, const char* nameorval, union ATOMICS* converter);
static int downConvert(union ATOMICS* converter, NCD4node* type);
static void freeStringMemory(char** mem, int count);
static void freeStringMemory(char** mem, size_t count);
static size_t getDimrefs(NCD4node* var, int* dimids);
static size_t getDimsizes(NCD4node* var, int* dimsizes);
static d4size_t getpadding(d4size_t offset, size_t alignment);
Expand Down Expand Up @@ -255,7 +255,7 @@ buildDimension(NCD4meta* builder, NCD4node* dim)
if(dim->dim.isunlimited) {
NCCHECK((nc_def_dim(group->meta.id,dim->name,NC_UNLIMITED,&dim->meta.id)));
} else {
NCCHECK((nc_def_dim(group->meta.id,dim->name,(size_t)dim->dim.size,&dim->meta.id)));
NCCHECK((nc_def_dim(group->meta.id,dim->name,dim->dim.size,&dim->meta.id)));
}
done:
return THROW(ret);
Expand Down Expand Up @@ -535,7 +535,7 @@ buildAtomicVar(NCD4meta* builder, NCD4node* var)
#endif

rank = getDimrefs(var,dimids);
NCCHECK((nc_def_var(group->meta.id,var->name,var->basetype->meta.id,rank,dimids,&var->meta.id)));
NCCHECK((nc_def_var(group->meta.id,var->name,var->basetype->meta.id,(int)rank,dimids,&var->meta.id)));
/* Tag the var */
savevarbyid(group,var);

Expand Down Expand Up @@ -705,11 +705,10 @@ getDimsizes(NCD4node* var, int* dimsizes)
/* Utilities */

static void
freeStringMemory(char** mem, int count)
freeStringMemory(char** mem, size_t count)
{
int i;
if(mem == NULL) return;
for(i=0;i<count;i++) {
for(size_t i=0;i<count;i++) {
char* p = mem[i];
if(p) free(p);
}
Expand Down
5 changes: 2 additions & 3 deletions libdap4/d4odom.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ d4odom_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;
size_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);
Expand Down Expand Up @@ -98,14 +98,13 @@ d4odom_more(D4odometer* odom)
d4size_t
d4odom_next(D4odometer* odom)
{
int i; /* do not make unsigned */
d4size_t count;
if(odom->rank == 0) { /*scalar*/
odom->index[0]++;
return 0;
}
count = d4odom_offset(odom); /* convenience */
for(i=odom->rank-1;i>=0;i--) {
for(size_t i=odom->rank; i-- >0;) {
odom->index[i] += odom->stride[i];
if(odom->index[i] < odom->stop[i]) break;
if(i == 0) break; /* leave the 0th entry if it overflows*/
Expand Down
2 changes: 1 addition & 1 deletion libdap4/d4odom.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#define D4ODOM_H 1

typedef struct D4odometer {
int rank;
size_t rank;
size_t index[NC_MAX_VAR_DIMS];
size_t start[NC_MAX_VAR_DIMS];
#if 0
Expand Down
31 changes: 15 additions & 16 deletions libdap4/d4parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ parseDimensions(NCD4parser* parser, NCD4node* group, ncxml_t xml)
if((ret = parseULL(sizestr,&size))) goto done;
nullfree(sizestr);
if((ret=makeNode(parser,group,x,NCD4_DIM,NC_NULL,&dimnode))) goto done;
dimnode->dim.size = (long long)size;
dimnode->dim.size = size;
dimnode->dim.isunlimited = (unlimstr != NULL);
nullfree(unlimstr);
/* Process attributes */
Expand Down Expand Up @@ -881,7 +881,7 @@ getOpaque(NCD4parser* parser, ncxml_t varxml, NCD4node* group)
{
size_t i;
int ret = NC_NOERR;
long long len;
size_t len;
NCD4node* opaquetype = NULL;
char* xattr;

Expand All @@ -894,11 +894,11 @@ getOpaque(NCD4parser* parser, ncxml_t varxml, NCD4node* group)
/* See if this var has UCARTAGOPAQUE attribute */
xattr = ncxml_attr(varxml,UCARTAGOPAQUE);
if(xattr != NULL) {
long long tmp = 0;
long long tmp = 0;
if((ret = parseLL(xattr,&tmp)) || (tmp < 0))
FAIL(NC_EINVAL,"Illegal opaque len: %s",xattr);
len = tmp;
nullfree(xattr);
FAIL(NC_EINVAL,"Illegal opaque len: %s",xattr);
len = (size_t)tmp;
nullfree(xattr);
}
}
#ifndef FIXEDOPAQUE
Expand All @@ -920,7 +920,7 @@ getOpaque(NCD4parser* parser, ncxml_t varxml, NCD4node* group)
if(opaquetype == NULL) {/* create it */
char name[NC_MAX_NAME+1];
/* Make name be "opaqueN" */
snprintf(name,NC_MAX_NAME,"opaque%lld_t",len);
snprintf(name,NC_MAX_NAME,"opaque%zu_t",len);
/* Opaque types are always created in the current group */
if((ret=makeNode(parser,group,NULL,NCD4_TYPE,NC_OPAQUE,&opaquetype)))
goto done;
Expand Down Expand Up @@ -1098,14 +1098,13 @@ lookupFQNList(NCD4parser* parser, NClist* fqn, NCD4sort sort, NCD4node** result)
{
int ret = NC_NOERR;
size_t i;
int nsteps;
NCD4node* current;
char* name = NULL;
NCD4node* node = NULL;

/* Step 1: walk thru groups until can go no further */
current = parser->metadata->root;
nsteps = nclistlength(fqn);
size_t nsteps = nclistlength(fqn);
for(i=1;i<nsteps;i++) { /* start at 1 to side-step root name */
assert(ISGROUP(current->sort));
name = (char*)nclistget(fqn,i);
Expand Down Expand Up @@ -1282,17 +1281,17 @@ defineAtomicTypes(NCD4meta* meta, NClist* list)
static NCD4node*
lookupAtomicType(NClist* atomictypes, const char* name)
{
int n = nclistlength(atomictypes);
int L = 0;
int R = (n - 1);
int m, cmp;
size_t n = nclistlength(atomictypes);
if (n == 0) return NULL;
size_t L = 0;
size_t R = n - 1;
NCD4node* p;

for(;;) {
if(L > R) break;
m = (L + R) / 2;
size_t m = (L + R) / 2;
p = (NCD4node*)nclistget(atomictypes,m);
cmp = strcasecmp(p->name,name);
int cmp = strcasecmp(p->name,name);
if(cmp == 0)
return p;
if(cmp < 0)
Expand Down Expand Up @@ -1370,7 +1369,7 @@ makeAnonDim(NCD4parser* parser, const char* sizestr)
if(dim == NULL) {/* create it */
if((ret=makeNode(parser,root,NULL,NCD4_DIM,NC_NULL,&dim))) goto done;
SETNAME(dim,name+1); /* leave out the '/' separator */
dim->dim.size = (long long)size;
dim->dim.size = (size_t)size;
dim->dim.isanonymous = 1;
classify(root,dim);
}
Expand Down
4 changes: 2 additions & 2 deletions libdap4/d4read.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ deltatime(struct timeval time0,struct timeval time1)
#endif

int
NCD4_readDMR(NCD4INFO* state, int flags, NCURI* url, NCD4response* resp)
NCD4_readDMR(NCD4INFO* state, NCURI* url, NCD4response* resp)
{
int stat = NC_NOERR;
ncbytesclear(state->curl->packet);
Expand All @@ -46,7 +46,7 @@ NCD4_readDMR(NCD4INFO* state, int flags, NCURI* url, NCD4response* resp)
}

int
NCD4_readDAP(NCD4INFO* state, int flags, NCURI* url, NCD4response* resp)
NCD4_readDAP(NCD4INFO* state, NCURI* url, NCD4response* resp)
{
int stat = NC_NOERR;

Expand Down
7 changes: 4 additions & 3 deletions libdap4/d4swap.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stdarg.h>
#include <stddef.h>
#include "d4includes.h"
#include "d4util.h"

/*
The primary purpose of this code is to recursively traverse
Expand Down Expand Up @@ -51,7 +52,7 @@ NCD4_swapdata(NCD4response* resp, NCD4node* var, int doswap)
if((ret=walkSeqArray(resp,var,var,offset,doswap))) goto done;
break;
}
var->data.dap4data.size = DELTA(offset,var->data.dap4data.memory);
var->data.dap4data.size = (d4size_t)DELTA(offset,var->data.dap4data.memory);
/* skip checksum, if there is one */
if(resp->inferredchecksumming)
INCR(offset,CHECKSUMSIZE);
Expand All @@ -77,8 +78,8 @@ walkAtomicVar(NCD4response* resp, NCD4node* topvar, NCD4node* var, NCD4offset* o
subsort = var->basetype->basetype->subsort;
/* Only need to swap multi-byte integers and floats */
if(subsort != NC_STRING) {
int typesize = NCD4_typesize(subsort);
d4size_t totalsize = typesize*dimproduct;
size_t typesize = NCD4_typesize(subsort);
d4size_t totalsize = typesize*dimproduct;
if(typesize == 1) {
INCR(offset,totalsize);
} else { /*(typesize > 1)*/
Expand Down
2 changes: 1 addition & 1 deletion libdap4/d4util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef struct D4blob {d4size_t size; void* memory;} D4blob;
/* Empty blob constant */
#define NULLBLOB(blob) {blob.size = 0; blob.memory = NULL;}

#define OFFSET2BLOB(blob,offset) do{(blob).size = ((offset)->limit - (offset)->base); (blob).memory = (offset)->base; }while(0)
#define OFFSET2BLOB(blob,offset) do{(blob).size = (d4size_t)((offset)->limit - (offset)->base); (blob).memory = (offset)->base; }while(0)
#define BLOB2OFFSET(offset,blob) do{\
(offset)->base = (blob).memory; \
(offset)->limit = ((char*)(blob).memory) + (blob).size; \
Expand Down
4 changes: 2 additions & 2 deletions libdap4/d4varx.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ NCD4_get_vars(int gid, int varid,
/* build size vector */
for(i=0;i<rank;i++) {
NCD4node* dim = nclistget(ncvar->dims,i);
dimsizes[i] = (size_t)dim->dim.size;
dimsizes[i] = dim->dim.size;
}

/* Extract and desired subset of data */
Expand Down Expand Up @@ -195,7 +195,7 @@ getvarx(int gid, int varid, NCD4INFO** infop, NCD4node** varp,
if((ret=NCD4_newResponse(info,&dapresp))) goto done;
dapresp->mode = NCD4_DAP;
nclistpush(info->responses,dapresp);
if((ret=NCD4_readDAP(info, info->controls.flags.flags, ceuri, dapresp))) goto done;
if((ret=NCD4_readDAP(info, ceuri, dapresp))) goto done;

/* Extract DMR and dechunk the data part */
if((ret=NCD4_dechunk(dapresp))) goto done;
Expand Down
4 changes: 2 additions & 2 deletions libdap4/ncd4.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ EXTERNL int NCD4_fetchlastmodified(CURL* curl, char* url, long* filetime);
EXTERNL int NCD4_ping(const char* url);

/* From d4read.c */
EXTERNL int NCD4_readDMR(NCD4INFO* state, int flags, NCURI* url, NCD4response*);
EXTERNL int NCD4_readDAP(NCD4INFO* state, int flags, NCURI* ceuri, NCD4response*);
EXTERNL int NCD4_readDMR(NCD4INFO* state, NCURI* url, NCD4response*);
EXTERNL int NCD4_readDAP(NCD4INFO* state, NCURI* ceuri, NCD4response*);
EXTERNL int NCD4_seterrormessage(NCD4response*, size_t len, char* msg);

/* From d4parser.c */
Expand Down
5 changes: 3 additions & 2 deletions libdap4/ncd4types.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ are defined here.

#undef COMPILEBYDEFAULT

#include "ncdap.h"
#include "ncrc.h"
#include "ncauth.h"

Expand Down Expand Up @@ -206,10 +207,10 @@ struct NCD4node {
NClist* values;
} attr;
struct { /* sort == NCD4_OPAQUE */
long long size; /* 0 => var length */
size_t size; /* 0 => var length */
} opaque;
struct { /* sort == NCD4_DIMENSION */
long long size;
size_t size;
int isunlimited;
int isanonymous;
} dim;
Expand Down
Loading