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 conversion warnings in libdispatch #2905

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libdispatch/dauth.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ setauthfield(NCauth* auth, const char* flag, const char* value)
}
if(strcmp(flag,"HTTP.SSL.VERIFYPEER")==0) {
int v;
if((v = atol(value))) {
if((v = atoi(value))) {
auth->ssl.verifypeer = v;
#ifdef DEBUG
nclog(NCLOGNOTE,"HTTP.SSL.VERIFYPEER: %d", v);
Expand All @@ -290,7 +290,7 @@ setauthfield(NCauth* auth, const char* flag, const char* value)
}
if(strcmp(flag,"HTTP.SSL.VERIFYHOST")==0) {
int v;
if((v = atol(value))) {
if((v = atoi(value))) {
auth->ssl.verifyhost = v;
#ifdef DEBUG
nclog(NCLOGNOTE,"HTTP.SSL.VERIFYHOST: %d", v);
Expand Down
4 changes: 1 addition & 3 deletions libdispatch/daux.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,9 @@ computefieldinfo(struct NCAUX_CMPD* cmpd)
#define LBRACK '['
#define RBRACK ']'

static int gettype(int q0, int q1, int* unsignedp);

/* Look at q0 and q1) to determine type */
static int
gettype(const int q0, const int q1, int* isunsignedp)
gettype(const char q0, const char q1, int* isunsignedp)
{
int type = 0;
int isunsigned = 0;
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dhttp.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size)

/* show data on the right */
for(c = 0; (c < width) && (i+c < size); c++) {
char x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
const int x = (ptr[i+c] >= 0x20 && ptr[i+c] < 0x80) ? ptr[i+c] : '.';
fputc(x, stream);
}

Expand Down
12 changes: 6 additions & 6 deletions libdispatch/dinfermodel.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ static int parseonchar(const char* s, int ch, NClist* segments);
static int mergelist(NClist** valuesp);

static int openmagic(struct MagicFile* file);
static int readmagic(struct MagicFile* file, long pos, char* magic);
static int readmagic(struct MagicFile* file, size_t pos, char* magic);
static int closemagic(struct MagicFile* file);
static int NC_interpret_magic_number(char* magic, NCmodel* model);
#ifdef DEBUG
Expand Down Expand Up @@ -1288,7 +1288,7 @@ check_file_type(const char *path, int omode, int use_parallel,
search forward at starting at 512
and doubling to see if we have HDF5 magic number */
{
long pos = 512L;
size_t pos = 512L;
for(;;) {
if((pos+MAGIC_NUMBER_LEN) > magicinfo.filelen)
{status = NC_ENOTNC; goto done;}
Expand Down Expand Up @@ -1395,7 +1395,7 @@ openmagic(struct MagicFile* file)
}

static int
readmagic(struct MagicFile* file, long pos, char* magic)
readmagic(struct MagicFile* file, size_t pos, char* magic)
{
int status = NC_NOERR;
NCbytes* buf = ncbytesnew();
Expand All @@ -1413,8 +1413,8 @@ readmagic(struct MagicFile* file, long pos, char* magic)
#endif
} else if(file->uri != NULL) {
#ifdef NETCDF_ENABLE_BYTERANGE
fileoffset_t start = (size_t)pos;
fileoffset_t count = MAGIC_NUMBER_LEN;
size64_t start = (size64_t)pos;
size64_t count = MAGIC_NUMBER_LEN;
status = nc_http_read(file->state, start, count, buf);
if (status == NC_NOERR) {
if (ncbyteslength(buf) != count)
Expand All @@ -1436,7 +1436,7 @@ readmagic(struct MagicFile* file, long pos, char* magic)
#endif /* USE_PARALLEL */
{ /* Ordinary read */
long i;
i = fseek(file->fp, pos, SEEK_SET);
i = fseek(file->fp, (long)pos, SEEK_SET);
if (i < 0) { status = errno; goto done; }
ncbytessetlength(buf, 0);
if ((status = NC_readfileF(file->fp, buf, MAGIC_NUMBER_LEN))) goto done;
Expand Down
22 changes: 12 additions & 10 deletions libdispatch/dinstance.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Currently two operations are defined:
*/

#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Expand Down Expand Up @@ -411,7 +413,7 @@ dump_datar(int ncid, nc_type xtype, Position* offset, NCbytes* buf)
break;
}
if(xtype <= NC_MAX_ATOMIC_TYPE)
offset->offset += xsize;
offset->offset += (ptrdiff_t)xsize;

done:
return stat;
Expand Down Expand Up @@ -440,12 +442,12 @@ dump_vlen(int ncid, nc_type xtype, nc_type basetype, Position* offset, NCbytes*
voffset.offset = 0;
for(i=0;i<vl->len;i++) {
if(i > 0) ncbytescat(buf," ");
voffset.offset = NC_read_align(voffset.offset,alignment);
voffset.offset = (ptrdiff_t)NC_read_align((uintptr_t)voffset.offset, alignment);
if((stat = dump_datar(ncid,basetype,&voffset,buf))) goto done;
}
}
ncbytescat(buf,")}");
offset->offset += sizeof(nc_vlen_t);
offset->offset += (ptrdiff_t)sizeof(nc_vlen_t);

done:
return stat;
Expand All @@ -469,20 +471,20 @@ dump_opaque(int ncid, nc_type xtype, size_t size, Position* offset, NCbytes* buf
/* basically a fixed size sequence of bytes */
ncbytescat(buf,"|");
for(i=0;i<size;i++) {
unsigned char x = *(offset->memory+offset->offset+i);
unsigned char x = (unsigned char)*(offset->memory+offset->offset+i);
snprintf(sx,sizeof(sx),"%2x",x);
ncbytescat(buf,sx);
}
ncbytescat(buf,"|");
offset->offset += size;
offset->offset += (ptrdiff_t)size;
return NC_NOERR;
}

static int
dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* offset, NCbytes* buf)
{
int stat = NC_NOERR;
size_t fid, i, arraycount;
size_t i;
ptrdiff_t saveoffset;
int ndims;
int dimsizes[NC_MAX_VAR_DIMS];
Expand All @@ -492,7 +494,7 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
ncbytescat(buf,"<");

/* Get info about each field in turn and dump it */
for(fid=0;fid<nfields;fid++) {
for(int fid=0;fid<nfields;fid++) {
size_t fieldalignment;
nc_type fieldtype;
char name[NC_MAX_NAME];
Expand All @@ -513,9 +515,9 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
ncbytescat(buf,")");
if(ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */
/* Align to this field */
offset->offset = saveoffset + fieldalignment;
offset->offset = saveoffset + (ptrdiff_t)fieldalignment;
/* compute the total number of elements in the field array */
arraycount = 1;
int arraycount = 1;
for(i=0;i<ndims;i++) arraycount *= dimsizes[i];
for(i=0;i<arraycount;i++) {
if(i > 0) ncbytescat(buf," ");
Expand All @@ -525,7 +527,7 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
ncbytescat(buf,">");
/* Return to beginning of the compound and move |compound| */
offset->offset = saveoffset;
offset->offset += size;
offset->offset += (ptrdiff_t)size;

done:
return stat;
Expand Down
6 changes: 3 additions & 3 deletions libdispatch/dinstance_intern.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ reclaim_datar(NC_FILE_INFO_T* file, NC_TYPE_INFO_T* utype, Position instance)
NC_TYPE_INFO_T* basetype = NULL;
size_t nfields;
nc_vlen_t* vlen;
size_t fid, arraycount;
size_t fid;
int ndims;
int dimsizes[NC_MAX_VAR_DIMS];
size_t alignment = 0;
Expand Down Expand Up @@ -184,7 +184,7 @@ reclaim_datar(NC_FILE_INFO_T* file, NC_TYPE_INFO_T* utype, Position instance)
/* Get field's dimension sizes */
field = (NC_FIELD_INFO_T*)nclistget(utype->u.c.field,fid);
ndims = field->ndims;
arraycount = 1;
int arraycount = 1;
for(i=0;i<ndims;i++) {dimsizes[i] = field->dim_size[i]; arraycount *= dimsizes[i];}
if(field->ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */

Expand Down Expand Up @@ -423,7 +423,7 @@ copy_datar(NC_FILE_INFO_T* file, NC_TYPE_INFO_T* utype, Position src, Position d
field = (NC_FIELD_INFO_T*)nclistget(utype->u.c.field,fid);
ndims = field->ndims;
arraycount = 1;
for(i=0;i<ndims;i++) {dimsizes[i] = field->dim_size[i]; arraycount *= dimsizes[i];}
for(i=0;i<ndims;i++) {dimsizes[i] = field->dim_size[i]; arraycount *= (size_t)dimsizes[i];}
if(field->ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */

/* "move" to this field */
Expand Down
4 changes: 2 additions & 2 deletions libdispatch/dpathmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static const char* cygwinspecial[] =

static const struct Path {
int kind;
int drive;
char drive;
char* path;
} empty = {NCPD_UNKNOWN,0,NULL};

Expand Down Expand Up @@ -896,7 +896,7 @@ unparsepath(struct Path* xp, char** pathp, int target)
char sdrive[4] = "\0\0\0\0";
char* p = NULL;
int cygspecial = 0;
int drive = 0;
char drive = 0;

/* Short circuit a relative path */
if(xp->kind == NCPD_REL) {
Expand Down
29 changes: 12 additions & 17 deletions libdispatch/ds3util.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,10 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp)
static int
endswith(const char* s, const char* suffix)
{
ssize_t ls, lsf, delta;
if(s == NULL || suffix == NULL) return 0;
ls = strlen(s);
lsf = strlen(suffix);
delta = (ls - lsf);
size_t ls = strlen(s);
size_t lsf = strlen(suffix);
ssize_t delta = (ssize_t)(ls - lsf);
if(delta < 0) return 0;
if(memcmp(s+delta,suffix,lsf)!=0) return 0;
return 1;
Expand Down Expand Up @@ -404,11 +403,10 @@ static void
freeprofile(struct AWSprofile* profile)
{
if(profile) {
int i;
#ifdef AWSDEBUG
fprintf(stderr,">>> freeprofile: %s\n",profile->name);
#endif
for(i=0;i<nclistlength(profile->entries);i++) {
for(size_t i=0;i<nclistlength(profile->entries);i++) {
struct AWSentry* e = (struct AWSentry*)nclistget(profile->entries,i);
freeentry(e);
}
Expand All @@ -422,8 +420,7 @@ void
NC_s3freeprofilelist(NClist* profiles)
{
if(profiles) {
int i;
for(i=0;i<nclistlength(profiles);i++) {
for(size_t i=0;i<nclistlength(profiles);i++) {
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
freeprofile(p);
}
Expand Down Expand Up @@ -549,10 +546,9 @@ int
NC_authgets3profile(const char* profilename, struct AWSprofile** profilep)
{
int stat = NC_NOERR;
int i = -1;
NCglobalstate* gstate = NC_getglobalstate();

for(i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
for(size_t i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
struct AWSprofile* profile = (struct AWSprofile*)nclistget(gstate->rcinfo->s3profiles,i);
if(strcmp(profilename,profile->name)==0)
{if(profilep) {*profilep = profile; goto done;}}
Expand All @@ -572,13 +568,13 @@ NC_authgets3profile(const char* profilename, struct AWSprofile** profilep)
int
NC_s3profilelookup(const char* profile, const char* key, const char** valuep)
{
int i,stat = NC_NOERR;
int stat = NC_NOERR;
struct AWSprofile* awsprof = NULL;
const char* value = NULL;

if(profile == NULL) return NC_ES3;
if((stat=NC_authgets3profile(profile,&awsprof))==NC_NOERR && awsprof != NULL) {
for(i=0;i<nclistlength(awsprof->entries);i++) {
for(size_t i=0;i<nclistlength(awsprof->entries);i++) {
struct AWSentry* entry = (struct AWSentry*)nclistget(awsprof->entries,i);
if(strcasecmp(entry->key,key)==0) {
value = entry->value;
Expand Down Expand Up @@ -735,7 +731,6 @@ typedef struct AWSparser {
static int
awslex(AWSparser* parser)
{
int c;
int token = 0;
char* start;
size_t count;
Expand All @@ -751,7 +746,7 @@ awslex(AWSparser* parser)
}

while(token == 0) { /* avoid need to goto when retrying */
c = *parser->pos;
char c = *parser->pos;
if(c == '\0') {
token = AWS_EOF;
} else if(c == '\n') {
Expand Down Expand Up @@ -785,7 +780,7 @@ awslex(AWSparser* parser)
}
/* Pushback last char */
parser->pos--;
count = ((parser->pos) - start);
count = (size_t)(parser->pos - start);
ncbytesappendn(parser->yytext,start,count);
ncbytesnull(parser->yytext);
token = AWS_WORD;
Expand All @@ -811,7 +806,7 @@ fprintf(stderr,"%s(%d): |%s|\n",tokenname(token),token,ncbytescontents(parser->y
static int
awsparse(const char* text, NClist* profiles)
{
int i,stat = NC_NOERR;
int stat = NC_NOERR;
size_t len;
AWSparser* parser = NULL;
struct AWSprofile* profile = NULL;
Expand Down Expand Up @@ -891,7 +886,7 @@ fprintf(stderr,">>> parse: entry=(%s,%s)\n",entry->key,entry->value);
}

/* If this profile already exists, then replace old one */
for(i=0;i<nclistlength(profiles);i++) {
for(size_t i=0;i<nclistlength(profiles);i++) {
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
if(strcasecmp(p->name,profile->name)==0) {
nclistset(profiles,i,profile);
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dutf8.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ int nc_utf8_to_utf16(const unsigned char* s8, unsigned short** utf16p, size_t* l
goto done;
} else { /* move to next char */
/* Complain if top 16 bits not zero */
if((codepoint & 0xFFFF0000) != 0) {
if((codepoint & (nc_utf8proc_int32_t)0xFFFF0000) != 0) {
ncstat = NC_EBADNAME;
goto done;
}
Expand Down
7 changes: 3 additions & 4 deletions libdispatch/dutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount)
{
#define READ_BLOCK_SIZE 4194304
int ret = NC_NOERR;
long long red = 0;
size_t red = 0;
char *part = (char*) malloc(READ_BLOCK_SIZE);

while(amount < 0 || red < amount) {
Expand All @@ -294,7 +294,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount)
}
/* Keep only amount */
if(amount >= 0) {
if(red > amount) ncbytessetlength(content,amount); /* read too much */
if(red > amount) ncbytessetlength(content, (unsigned long)amount); /* read too much */
if(red < amount) ret = NC_ETRUNC; /* |file| < amount */
}
ncbytesnull(content);
Expand Down Expand Up @@ -405,7 +405,6 @@ NC_addmodetag(NCURI* uri, const char* tag)
{
int stat = NC_NOERR;
int found = 0;
int i;
const char* modestr = NULL;
char* modevalue = NULL;
NClist* modelist = NULL;
Expand All @@ -417,7 +416,7 @@ NC_addmodetag(NCURI* uri, const char* tag)
} else
modelist = nclistnew();
/* Search for tag */
for(i=0;i<nclistlength(modelist);i++) {
for(size_t i=0;i<nclistlength(modelist);i++) {
const char* mode = (const char*)nclistget(modelist,i);
if(strcasecmp(mode,tag)==0) {found = 1; break;}
}
Expand Down
2 changes: 1 addition & 1 deletion libdispatch/dv2i.c
Original file line number Diff line number Diff line change
Expand Up @@ -1411,7 +1411,7 @@ ncattput(
const void* value
)
{
const int status = nc_put_att(ncid, varid, name, datatype, len, value);
const int status = nc_put_att(ncid, varid, name, datatype, (size_t)len, value);
if(status != NC_NOERR)
{
nc_advise("ncattput", status, "ncid %d", ncid);
Expand Down
4 changes: 1 addition & 3 deletions libdispatch/dvar.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,7 @@ nc_def_var_szip(int ncid, int varid, int options_mask, int pixels_per_block)

/* This will cause H5Pset_szip to be called when the var is
* created. */
unsigned int params[2];
params[0] = options_mask;
params[1] = pixels_per_block;
unsigned int params[2] = {(unsigned int)options_mask, (unsigned int)pixels_per_block};
if ((ret = nc_def_var_filter(ncid, varid, HDF5_FILTER_SZIP, 2, params)))
return ret;

Expand Down
Loading
Loading