Skip to content

Commit fc02ef4

Browse files
authored
Merge pull request #2905 from ZedThree/silence-libdispatch-warnings
Fix conversion warnings in libdispatch
2 parents 2e40e7c + 7d111a7 commit fc02ef4

19 files changed

+85
-95
lines changed

libdispatch/dauth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ setauthfield(NCauth* auth, const char* flag, const char* value)
281281
}
282282
if(strcmp(flag,"HTTP.SSL.VERIFYPEER")==0) {
283283
int v;
284-
if((v = atol(value))) {
284+
if((v = atoi(value))) {
285285
auth->ssl.verifypeer = v;
286286
#ifdef DEBUG
287287
nclog(NCLOGNOTE,"HTTP.SSL.VERIFYPEER: %d", v);
@@ -290,7 +290,7 @@ setauthfield(NCauth* auth, const char* flag, const char* value)
290290
}
291291
if(strcmp(flag,"HTTP.SSL.VERIFYHOST")==0) {
292292
int v;
293-
if((v = atol(value))) {
293+
if((v = atoi(value))) {
294294
auth->ssl.verifyhost = v;
295295
#ifdef DEBUG
296296
nclog(NCLOGNOTE,"HTTP.SSL.VERIFYHOST: %d", v);

libdispatch/daux.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,9 @@ computefieldinfo(struct NCAUX_CMPD* cmpd)
311311
#define LBRACK '['
312312
#define RBRACK ']'
313313

314-
static int gettype(int q0, int q1, int* unsignedp);
315-
316314
/* Look at q0 and q1) to determine type */
317315
static int
318-
gettype(const int q0, const int q1, int* isunsignedp)
316+
gettype(const char q0, const char q1, int* isunsignedp)
319317
{
320318
int type = 0;
321319
int isunsigned = 0;

libdispatch/dhttp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size)
774774

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

libdispatch/dinfermodel.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static int parseonchar(const char* s, int ch, NClist* segments);
213213
static int mergelist(NClist** valuesp);
214214

215215
static int openmagic(struct MagicFile* file);
216-
static int readmagic(struct MagicFile* file, long pos, char* magic);
216+
static int readmagic(struct MagicFile* file, size_t pos, char* magic);
217217
static int closemagic(struct MagicFile* file);
218218
static int NC_interpret_magic_number(char* magic, NCmodel* model);
219219
#ifdef DEBUG
@@ -1288,7 +1288,7 @@ check_file_type(const char *path, int omode, int use_parallel,
12881288
search forward at starting at 512
12891289
and doubling to see if we have HDF5 magic number */
12901290
{
1291-
long pos = 512L;
1291+
size_t pos = 512L;
12921292
for(;;) {
12931293
if((pos+MAGIC_NUMBER_LEN) > magicinfo.filelen)
12941294
{status = NC_ENOTNC; goto done;}
@@ -1395,7 +1395,7 @@ openmagic(struct MagicFile* file)
13951395
}
13961396

13971397
static int
1398-
readmagic(struct MagicFile* file, long pos, char* magic)
1398+
readmagic(struct MagicFile* file, size_t pos, char* magic)
13991399
{
14001400
int status = NC_NOERR;
14011401
NCbytes* buf = ncbytesnew();
@@ -1413,8 +1413,8 @@ readmagic(struct MagicFile* file, long pos, char* magic)
14131413
#endif
14141414
} else if(file->uri != NULL) {
14151415
#ifdef NETCDF_ENABLE_BYTERANGE
1416-
fileoffset_t start = (size_t)pos;
1417-
fileoffset_t count = MAGIC_NUMBER_LEN;
1416+
size64_t start = (size64_t)pos;
1417+
size64_t count = MAGIC_NUMBER_LEN;
14181418
status = nc_http_read(file->state, start, count, buf);
14191419
if (status == NC_NOERR) {
14201420
if (ncbyteslength(buf) != count)
@@ -1436,7 +1436,7 @@ readmagic(struct MagicFile* file, long pos, char* magic)
14361436
#endif /* USE_PARALLEL */
14371437
{ /* Ordinary read */
14381438
long i;
1439-
i = fseek(file->fp, pos, SEEK_SET);
1439+
i = fseek(file->fp, (long)pos, SEEK_SET);
14401440
if (i < 0) { status = errno; goto done; }
14411441
ncbytessetlength(buf, 0);
14421442
if ((status = NC_readfileF(file->fp, buf, MAGIC_NUMBER_LEN))) goto done;

libdispatch/dinstance.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Currently two operations are defined:
1212
*/
1313

1414
#include "config.h"
15+
#include <stddef.h>
16+
#include <stdint.h>
1517
#include <stdlib.h>
1618
#include <string.h>
1719
#include <assert.h>
@@ -411,7 +413,7 @@ dump_datar(int ncid, nc_type xtype, Position* offset, NCbytes* buf)
411413
break;
412414
}
413415
if(xtype <= NC_MAX_ATOMIC_TYPE)
414-
offset->offset += xsize;
416+
offset->offset += (ptrdiff_t)xsize;
415417

416418
done:
417419
return stat;
@@ -440,12 +442,12 @@ dump_vlen(int ncid, nc_type xtype, nc_type basetype, Position* offset, NCbytes*
440442
voffset.offset = 0;
441443
for(i=0;i<vl->len;i++) {
442444
if(i > 0) ncbytescat(buf," ");
443-
voffset.offset = NC_read_align(voffset.offset,alignment);
445+
voffset.offset = (ptrdiff_t)NC_read_align((uintptr_t)voffset.offset, alignment);
444446
if((stat = dump_datar(ncid,basetype,&voffset,buf))) goto done;
445447
}
446448
}
447449
ncbytescat(buf,")}");
448-
offset->offset += sizeof(nc_vlen_t);
450+
offset->offset += (ptrdiff_t)sizeof(nc_vlen_t);
449451

450452
done:
451453
return stat;
@@ -469,20 +471,20 @@ dump_opaque(int ncid, nc_type xtype, size_t size, Position* offset, NCbytes* buf
469471
/* basically a fixed size sequence of bytes */
470472
ncbytescat(buf,"|");
471473
for(i=0;i<size;i++) {
472-
unsigned char x = *(offset->memory+offset->offset+i);
474+
unsigned char x = (unsigned char)*(offset->memory+offset->offset+i);
473475
snprintf(sx,sizeof(sx),"%2x",x);
474476
ncbytescat(buf,sx);
475477
}
476478
ncbytescat(buf,"|");
477-
offset->offset += size;
479+
offset->offset += (ptrdiff_t)size;
478480
return NC_NOERR;
479481
}
480482

481483
static int
482484
dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* offset, NCbytes* buf)
483485
{
484486
int stat = NC_NOERR;
485-
size_t fid, i, arraycount;
487+
size_t i;
486488
ptrdiff_t saveoffset;
487489
int ndims;
488490
int dimsizes[NC_MAX_VAR_DIMS];
@@ -492,7 +494,7 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
492494
ncbytescat(buf,"<");
493495

494496
/* Get info about each field in turn and dump it */
495-
for(fid=0;fid<nfields;fid++) {
497+
for(int fid=0;fid<nfields;fid++) {
496498
size_t fieldalignment;
497499
nc_type fieldtype;
498500
char name[NC_MAX_NAME];
@@ -513,9 +515,9 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
513515
ncbytescat(buf,")");
514516
if(ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */
515517
/* Align to this field */
516-
offset->offset = saveoffset + fieldalignment;
518+
offset->offset = saveoffset + (ptrdiff_t)fieldalignment;
517519
/* compute the total number of elements in the field array */
518-
arraycount = 1;
520+
int arraycount = 1;
519521
for(i=0;i<ndims;i++) arraycount *= dimsizes[i];
520522
for(i=0;i<arraycount;i++) {
521523
if(i > 0) ncbytescat(buf," ");
@@ -525,7 +527,7 @@ dump_compound(int ncid, nc_type xtype, size_t size, size_t nfields, Position* of
525527
ncbytescat(buf,">");
526528
/* Return to beginning of the compound and move |compound| */
527529
offset->offset = saveoffset;
528-
offset->offset += size;
530+
offset->offset += (ptrdiff_t)size;
529531

530532
done:
531533
return stat;

libdispatch/dinstance_intern.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ reclaim_datar(NC_FILE_INFO_T* file, NC_TYPE_INFO_T* utype, Position instance)
133133
NC_TYPE_INFO_T* basetype = NULL;
134134
size_t nfields;
135135
nc_vlen_t* vlen;
136-
size_t fid, arraycount;
136+
size_t fid;
137137
int ndims;
138138
int dimsizes[NC_MAX_VAR_DIMS];
139139
size_t alignment = 0;
@@ -184,7 +184,7 @@ reclaim_datar(NC_FILE_INFO_T* file, NC_TYPE_INFO_T* utype, Position instance)
184184
/* Get field's dimension sizes */
185185
field = (NC_FIELD_INFO_T*)nclistget(utype->u.c.field,fid);
186186
ndims = field->ndims;
187-
arraycount = 1;
187+
int arraycount = 1;
188188
for(i=0;i<ndims;i++) {dimsizes[i] = field->dim_size[i]; arraycount *= dimsizes[i];}
189189
if(field->ndims == 0) {ndims=1; dimsizes[0]=1;} /* fake the scalar case */
190190

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

429429
/* "move" to this field */

libdispatch/dpathmgr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static const char* cygwinspecial[] =
8585

8686
static const struct Path {
8787
int kind;
88-
int drive;
88+
char drive;
8989
char* path;
9090
} empty = {NCPD_UNKNOWN,0,NULL};
9191

@@ -896,7 +896,7 @@ unparsepath(struct Path* xp, char** pathp, int target)
896896
char sdrive[4] = "\0\0\0\0";
897897
char* p = NULL;
898898
int cygspecial = 0;
899-
int drive = 0;
899+
char drive = 0;
900900

901901
/* Short circuit a relative path */
902902
if(xp->kind == NCPD_REL) {

libdispatch/ds3util.c

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,10 @@ NC_s3urlrebuild(NCURI* url, NCS3INFO* s3, NCURI** newurlp)
282282
static int
283283
endswith(const char* s, const char* suffix)
284284
{
285-
ssize_t ls, lsf, delta;
286285
if(s == NULL || suffix == NULL) return 0;
287-
ls = strlen(s);
288-
lsf = strlen(suffix);
289-
delta = (ls - lsf);
286+
size_t ls = strlen(s);
287+
size_t lsf = strlen(suffix);
288+
ssize_t delta = (ssize_t)(ls - lsf);
290289
if(delta < 0) return 0;
291290
if(memcmp(s+delta,suffix,lsf)!=0) return 0;
292291
return 1;
@@ -404,11 +403,10 @@ static void
404403
freeprofile(struct AWSprofile* profile)
405404
{
406405
if(profile) {
407-
int i;
408406
#ifdef AWSDEBUG
409407
fprintf(stderr,">>> freeprofile: %s\n",profile->name);
410408
#endif
411-
for(i=0;i<nclistlength(profile->entries);i++) {
409+
for(size_t i=0;i<nclistlength(profile->entries);i++) {
412410
struct AWSentry* e = (struct AWSentry*)nclistget(profile->entries,i);
413411
freeentry(e);
414412
}
@@ -422,8 +420,7 @@ void
422420
NC_s3freeprofilelist(NClist* profiles)
423421
{
424422
if(profiles) {
425-
int i;
426-
for(i=0;i<nclistlength(profiles);i++) {
423+
for(size_t i=0;i<nclistlength(profiles);i++) {
427424
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
428425
freeprofile(p);
429426
}
@@ -549,10 +546,9 @@ int
549546
NC_authgets3profile(const char* profilename, struct AWSprofile** profilep)
550547
{
551548
int stat = NC_NOERR;
552-
int i = -1;
553549
NCglobalstate* gstate = NC_getglobalstate();
554550

555-
for(i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
551+
for(size_t i=0;i<nclistlength(gstate->rcinfo->s3profiles);i++) {
556552
struct AWSprofile* profile = (struct AWSprofile*)nclistget(gstate->rcinfo->s3profiles,i);
557553
if(strcmp(profilename,profile->name)==0)
558554
{if(profilep) {*profilep = profile; goto done;}}
@@ -572,13 +568,13 @@ NC_authgets3profile(const char* profilename, struct AWSprofile** profilep)
572568
int
573569
NC_s3profilelookup(const char* profile, const char* key, const char** valuep)
574570
{
575-
int i,stat = NC_NOERR;
571+
int stat = NC_NOERR;
576572
struct AWSprofile* awsprof = NULL;
577573
const char* value = NULL;
578574

579575
if(profile == NULL) return NC_ES3;
580576
if((stat=NC_authgets3profile(profile,&awsprof))==NC_NOERR && awsprof != NULL) {
581-
for(i=0;i<nclistlength(awsprof->entries);i++) {
577+
for(size_t i=0;i<nclistlength(awsprof->entries);i++) {
582578
struct AWSentry* entry = (struct AWSentry*)nclistget(awsprof->entries,i);
583579
if(strcasecmp(entry->key,key)==0) {
584580
value = entry->value;
@@ -735,7 +731,6 @@ typedef struct AWSparser {
735731
static int
736732
awslex(AWSparser* parser)
737733
{
738-
int c;
739734
int token = 0;
740735
char* start;
741736
size_t count;
@@ -751,7 +746,7 @@ awslex(AWSparser* parser)
751746
}
752747

753748
while(token == 0) { /* avoid need to goto when retrying */
754-
c = *parser->pos;
749+
char c = *parser->pos;
755750
if(c == '\0') {
756751
token = AWS_EOF;
757752
} else if(c == '\n') {
@@ -785,7 +780,7 @@ awslex(AWSparser* parser)
785780
}
786781
/* Pushback last char */
787782
parser->pos--;
788-
count = ((parser->pos) - start);
783+
count = (size_t)(parser->pos - start);
789784
ncbytesappendn(parser->yytext,start,count);
790785
ncbytesnull(parser->yytext);
791786
token = AWS_WORD;
@@ -811,7 +806,7 @@ fprintf(stderr,"%s(%d): |%s|\n",tokenname(token),token,ncbytescontents(parser->y
811806
static int
812807
awsparse(const char* text, NClist* profiles)
813808
{
814-
int i,stat = NC_NOERR;
809+
int stat = NC_NOERR;
815810
size_t len;
816811
AWSparser* parser = NULL;
817812
struct AWSprofile* profile = NULL;
@@ -891,7 +886,7 @@ fprintf(stderr,">>> parse: entry=(%s,%s)\n",entry->key,entry->value);
891886
}
892887

893888
/* If this profile already exists, then replace old one */
894-
for(i=0;i<nclistlength(profiles);i++) {
889+
for(size_t i=0;i<nclistlength(profiles);i++) {
895890
struct AWSprofile* p = (struct AWSprofile*)nclistget(profiles,i);
896891
if(strcasecmp(p->name,profile->name)==0) {
897892
nclistset(profiles,i,profile);

libdispatch/dutf8.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ int nc_utf8_to_utf16(const unsigned char* s8, unsigned short** utf16p, size_t* l
153153
goto done;
154154
} else { /* move to next char */
155155
/* Complain if top 16 bits not zero */
156-
if((codepoint & 0xFFFF0000) != 0) {
156+
if((codepoint & (nc_utf8proc_int32_t)0xFFFF0000) != 0) {
157157
ncstat = NC_EBADNAME;
158158
goto done;
159159
}

libdispatch/dutil.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount)
282282
{
283283
#define READ_BLOCK_SIZE 4194304
284284
int ret = NC_NOERR;
285-
long long red = 0;
285+
size_t red = 0;
286286
char *part = (char*) malloc(READ_BLOCK_SIZE);
287287

288288
while(amount < 0 || red < amount) {
@@ -294,7 +294,7 @@ NC_readfileF(FILE* stream, NCbytes* content, long long amount)
294294
}
295295
/* Keep only amount */
296296
if(amount >= 0) {
297-
if(red > amount) ncbytessetlength(content,amount); /* read too much */
297+
if(red > amount) ncbytessetlength(content, (unsigned long)amount); /* read too much */
298298
if(red < amount) ret = NC_ETRUNC; /* |file| < amount */
299299
}
300300
ncbytesnull(content);
@@ -405,7 +405,6 @@ NC_addmodetag(NCURI* uri, const char* tag)
405405
{
406406
int stat = NC_NOERR;
407407
int found = 0;
408-
int i;
409408
const char* modestr = NULL;
410409
char* modevalue = NULL;
411410
NClist* modelist = NULL;
@@ -417,7 +416,7 @@ NC_addmodetag(NCURI* uri, const char* tag)
417416
} else
418417
modelist = nclistnew();
419418
/* Search for tag */
420-
for(i=0;i<nclistlength(modelist);i++) {
419+
for(size_t i=0;i<nclistlength(modelist);i++) {
421420
const char* mode = (const char*)nclistget(modelist,i);
422421
if(strcasecmp(mode,tag)==0) {found = 1; break;}
423422
}

0 commit comments

Comments
 (0)