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

Silence most warnings in libsrc #2883

Merged
merged 3 commits into from
Mar 21, 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
2 changes: 1 addition & 1 deletion include/onstack.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#endif /* __GNUC__ */

# if !defined(ALLOCA_ARG_T)
# define ALLOCA_ARG_T int /* the usual type of the alloca argument */
# define ALLOCA_ARG_T size_t /* the usual type of the alloca argument */
# endif

# define ALLOC_ONSTACK(name, type, nelems) \
Expand Down
2 changes: 1 addition & 1 deletion libsrc/dim.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ NC3_rename_dim( int ncid, int dimid, const char *unewname)
NC_hashmapremove(ncp->dims.hashmap, old->cp, strlen(old->cp), NULL);
dimp->name = newStr;

intdata = dimid;
intdata = (uintptr_t)dimid;
NC_hashmapadd(ncp->dims.hashmap, intdata, newStr->cp, strlen(newStr->cp));
free_NC_string(old);
goto done;
Expand Down
4 changes: 2 additions & 2 deletions libsrc/httpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int httpio_filesize(ncio* nciop, off_t* filesizep);
static int httpio_pad_length(ncio* nciop, off_t length);
static int httpio_close(ncio* nciop, int);

static long pagesize = 0;
static size_t pagesize = 0;

/* Create a new ncio struct to hold info about the file. */
static int
Expand Down Expand Up @@ -261,7 +261,7 @@ httpio_get(ncio* const nciop, off_t offset, size_t extent, int rflags, void** co
assert(http->interval == NULL);
http->interval = ncbytesnew();
ncbytessetalloc(http->interval,(unsigned long)extent);
if((status = nc_http_read(http->state,offset,extent,http->interval)))
if((status = nc_http_read(http->state,(size64_t)offset,extent,http->interval)))
goto done;
assert(ncbyteslength(http->interval) == extent);
if(vpp) *vpp = ncbytescontents(http->interval);
Expand Down
18 changes: 9 additions & 9 deletions libsrc/memio.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
Expand Down Expand Up @@ -130,12 +131,12 @@ static size_t pagesize = 0;

/*! Create a new ncio struct to hold info about the file. */
static int
memio_new(const char* path, int ioflags, off_t initialsize, ncio** nciopp, NCMEMIO** memiop)
memio_new(const char* path, int ioflags, size_t initialsize, ncio** nciopp, NCMEMIO** memiop)
{
int status = NC_NOERR;
ncio* nciop = NULL;
NCMEMIO* memio = NULL;
size_t minsize = (size_t)initialsize;
size_t minsize = initialsize;

/* Unlike netcdf-4, INMEMORY and DISKLESS share code */
if(fIsSet(ioflags,NC_DISKLESS))
Expand Down Expand Up @@ -202,7 +203,7 @@ memio_new(const char* path, int ioflags, off_t initialsize, ncio** nciopp, NCMEM
nciop->path = NULL;
free(nciop);
}
memio->alloc = (size_t)initialsize;
memio->alloc = initialsize;
memio->pos = 0;
memio->size = minsize;
memio->memory = NULL; /* filled in by caller */
Expand Down Expand Up @@ -439,7 +440,7 @@ memio_filesize(ncio* nciop, off_t* filesizep)
NCMEMIO* memio;
if(nciop == NULL || nciop->pvt == NULL) return NC_EINVAL;
memio = (NCMEMIO*)nciop->pvt;
if(filesizep != NULL) *filesizep = memio->size;
if(filesizep != NULL) *filesizep = (off_t)memio->size;
return NC_NOERR;
}

Expand Down Expand Up @@ -542,14 +543,13 @@ static int
guarantee(ncio* nciop, off_t endpoint0)
{
NCMEMIO* memio = (NCMEMIO*)nciop->pvt;
size_t endpoint = (size_t)endpoint0;
if(endpoint > memio->alloc) {
if(endpoint0 > memio->alloc) {
/* extend the allocated memory and size */
int status = memio_pad_length(nciop,endpoint);
int status = memio_pad_length(nciop,endpoint0);
if(status != NC_NOERR) return status;
}
if(memio->size < endpoint)
memio->size = endpoint;
if(memio->size < endpoint0)
memio->size = (size_t)endpoint0;
return NC_NOERR;
}

Expand Down
36 changes: 18 additions & 18 deletions libsrc/mmapio.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ typedef struct NCMMAPIO {
int locked; /* => we cannot realloc */
int persist; /* => save to a file; triggered by NC_PERSIST */
char* memory;
off_t alloc;
size_t alloc;
off_t size;
off_t pos;
int mapfd;
Expand All @@ -111,11 +111,11 @@ static int mmapio_close(ncio* nciop, int);
/* Mnemonic */
#define DOOPEN 1

static long pagesize = 0;
static size_t pagesize = 0;

/* Create a new ncio struct to hold info about the file. */
static int
mmapio_new(const char* path, int ioflags, off_t initialsize, ncio** nciopp, NCMMAPIO** mmapp)
mmapio_new(const char* path, int ioflags, size_t initialsize, ncio** nciopp, NCMMAPIO** mmapp)
{
int status = NC_NOERR;
ncio* nciop = NULL;
Expand All @@ -124,9 +124,9 @@ mmapio_new(const char* path, int ioflags, off_t initialsize, ncio** nciopp, NCMM

if(pagesize == 0) {
#if defined HAVE_SYSCONF
pagesize = sysconf(_SC_PAGE_SIZE);
pagesize = (size_t)sysconf(_SC_PAGE_SIZE);
#elif defined HAVE_GETPAGESIZE
pagesize = getpagesize();
pagesize = (size_t)getpagesize();
#else
pagesize = 4096; /* good guess */
#endif
Expand Down Expand Up @@ -247,11 +247,11 @@ mmapio_create(const char* path, int ioflags,
if(fd < 0) {status = errno; goto unwind_open;}
mmapio->mapfd = fd;

{ /* Cause the output file to have enough allocated space */
lseek(fd,mmapio->alloc-1,SEEK_SET); /* cause file to appear */
write(fd,"",1);
lseek(fd,0,SEEK_SET); /* rewind */
}
{ /* Cause the output file to have enough allocated space */
lseek(fd,(off_t)mmapio->alloc-1,SEEK_SET); /* cause file to appear */
write(fd,"",1);
lseek(fd,0,SEEK_SET); /* rewind */
}
mmapio->memory = (char*)mmap(NULL,mmapio->alloc,
PROT_READ|PROT_WRITE,
MAP_SHARED,
Expand Down Expand Up @@ -313,7 +313,7 @@ mmapio_open(const char* path,
void* parameters,
ncio* *nciopp, void** const mempp)
{
ncio* nciop;
ncio* nciop = NULL;
int fd;
int status;
int oflags;
Expand Down Expand Up @@ -345,7 +345,7 @@ mmapio_open(const char* path,
if(filesize < (off_t)sizehint)
filesize = (off_t)sizehint;

status = mmapio_new(path, ioflags, filesize, &nciop, &mmapio);
status = mmapio_new(path, ioflags, (size_t)filesize, &nciop, &mmapio);
if(status != NC_NOERR)
return status;
mmapio->size = filesize;
Expand All @@ -360,7 +360,7 @@ fprintf(stderr,"mmapio_open: initial memory: %lu/%lu\n",(unsigned long)mmapio->m
#endif

/* Use half the filesize as the blocksize */
sizehint = filesize/2;
sizehint = (size_t)filesize/2;

/* sizehint must be multiple of 8 */
sizehint = (sizehint / 8) * 8;
Expand Down Expand Up @@ -425,7 +425,7 @@ mmapio_pad_length(ncio* nciop, off_t length)

if(length > mmapio->alloc) {
/* Realloc the allocated memory to a multiple of the pagesize*/
off_t newsize = length;
size_t newsize = (size_t)length;
void* newmem = NULL;
/* Round to a multiple of pagesize */
if((newsize % pagesize) != 0)
Expand All @@ -435,7 +435,7 @@ mmapio_pad_length(ncio* nciop, off_t length)
{ /* Cause the output file to have enough allocated space */
off_t pos = lseek(mmapio->mapfd,0,SEEK_CUR); /* save current position*/
/* cause file to be extended in size */
lseek(mmapio->mapfd,newsize-1,SEEK_SET);
lseek(mmapio->mapfd,(off_t)newsize-1,SEEK_SET);
write(mmapio->mapfd,"",mmapio->alloc);
lseek(mmapio->mapfd,pos,SEEK_SET); /* reset position */
}
Expand Down Expand Up @@ -524,7 +524,7 @@ mmapio_get(ncio* const nciop, off_t offset, size_t extent, int rflags, void** co
NCMMAPIO* mmapio;
if(nciop == NULL || nciop->pvt == NULL) return NC_EINVAL;
mmapio = (NCMMAPIO*)nciop->pvt;
status = guarantee(nciop, offset+extent);
status = guarantee(nciop, offset+(off_t)extent);
mmapio->locked++;
if(status != NC_NOERR) return status;
if(vpp) *vpp = mmapio->memory+offset;
Expand All @@ -544,11 +544,11 @@ mmapio_move(ncio* const nciop, off_t to, off_t from, size_t nbytes, int ignored)
mmapio = (NCMMAPIO*)nciop->pvt;
if(from < to) {
/* extend if "to" is not currently allocated */
status = guarantee(nciop,to+nbytes);
status = guarantee(nciop, to + (off_t)nbytes);
if(status != NC_NOERR) return status;
}
/* check for overlap */
if((to + nbytes) > from || (from + nbytes) > to) {
if((to + (off_t)nbytes) > from || (from + (off_t)nbytes) > to) {
/* Ranges overlap */
#ifdef HAVE_MEMMOVE
memmove((void*)(mmapio->memory+to),(void*)(mmapio->memory+from),nbytes);
Expand Down
32 changes: 16 additions & 16 deletions libsrc/nc3internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
Expand Down Expand Up @@ -153,7 +154,7 @@ NC_begins(NC3_INFO* ncp,
size_t v_minfree, size_t r_align)
{
size_t ii, j;
int sizeof_off_t;
size_t sizeof_off_t;
off_t index = 0;
off_t old_ncp_begin_var;
NC_var **vpp;
Expand Down Expand Up @@ -186,7 +187,7 @@ NC_begins(NC3_INFO* ncp,
{
index = (off_t) ncp->xsz;
ncp->begin_var = D_RNDUP(index, v_align);
if(ncp->begin_var < index + h_minfree)
if(ncp->begin_var < index + (off_t)h_minfree)
{
ncp->begin_var = D_RNDUP(index + (off_t)h_minfree, v_align);
}
Expand Down Expand Up @@ -253,11 +254,11 @@ fprintf(stderr, " VAR %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index);
/* only (re)calculate begin_rec if there is not sufficient
space at end of non-record variables or if start of record
variables is not aligned as requested by r_align */
if (ncp->begin_rec < index + v_minfree ||
if (ncp->begin_rec < index + (off_t)v_minfree ||
ncp->begin_rec != D_RNDUP(ncp->begin_rec, r_align) )
{
ncp->begin_rec = D_RNDUP(index, r_align);
if(ncp->begin_rec < index + v_minfree)
if(ncp->begin_rec < index + (off_t)v_minfree)
{
ncp->begin_rec = D_RNDUP(index + (off_t)v_minfree, r_align);
}
Expand Down Expand Up @@ -524,8 +525,8 @@ fill_added_recs(NC3_INFO *gnu, NC3_INFO *old)
{
NC_var ** const gnu_varpp = (NC_var **)gnu->vars.value;

const int old_nrecs = (int) NC_get_numrecs(old);
int recno = 0;
const size_t old_nrecs = NC_get_numrecs(old);
size_t recno = 0;
NC_var **vpp = gnu_varpp;
NC_var *const *const end = &vpp[gnu->vars.nelems];
int numrecvars = 0;
Expand Down Expand Up @@ -554,7 +555,7 @@ fill_added_recs(NC3_INFO *gnu, NC3_INFO *old)
}
/* else */
{
size_t varsize = numrecvars == 1 ? gnu->recsize : gnu_varp->len;
long long varsize = numrecvars == 1 ? gnu->recsize : gnu_varp->len;
const int status = fill_NC_var(gnu, gnu_varp, varsize, recno);
if(status != NC_NOERR)
return status;
Expand Down Expand Up @@ -629,8 +630,8 @@ move_recs_r(NC3_INFO *gnu, NC3_INFO *old)

/* else, a pre-existing variable */
old_varp = *(old_varpp + varid);
gnu_off = gnu_varp->begin + (off_t)(gnu->recsize * recno);
old_off = old_varp->begin + (off_t)(old->recsize * recno);
gnu_off = gnu_varp->begin + (off_t)(gnu->recsize * (size_t)recno);
old_off = old_varp->begin + (off_t)(old->recsize * (size_t)recno);

if(gnu_off == old_off)
continue; /* nothing to do */
Expand Down Expand Up @@ -955,7 +956,7 @@ NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep)

if(ncp->vars.nelems == 0) { /* no non-record variables and
no record variables */
*calcsizep = ncp->xsz; /* size of header */
*calcsizep = (off_t)ncp->xsz; /* size of header */
return NC_NOERR;
}

Expand All @@ -976,16 +977,15 @@ NC_calcsize(const NC3_INFO *ncp, off_t *calcsizep)
assert(last_fix != NULL);
varsize = last_fix->len;
if(last_fix->len == X_UINT_MAX) { /* huge last fixed var */
int i;
varsize = 1;
for(i = 0; i < last_fix->ndims; i++ ) {
varsize *= (last_fix->shape ? last_fix->shape[i] : 1);
}
for(size_t i = 0; i < last_fix->ndims; i++ ) {
varsize *= (last_fix->shape ? last_fix->shape[i] : 1);
}
}
*calcsizep = last_fix->begin + varsize;
/*last_var = last_fix;*/
} else { /* we have at least one record variable */
*calcsizep = ncp->begin_rec + ncp->numrecs * ncp->recsize;
*calcsizep = ncp->begin_rec + (off_t)(ncp->numrecs * ncp->recsize);
}

return NC_NOERR;
Expand Down Expand Up @@ -1021,7 +1021,7 @@ NC3_create(const char *path, int ioflags, size_t initialsz, int basepe,
{
int status = NC_NOERR;
void *xp = NULL;
int sizeof_off_t = 0;
size_t sizeof_off_t = 0;
NC *nc;
NC3_INFO* nc3 = NULL;

Expand Down
Loading
Loading