Skip to content

Commit

Permalink
Merge pull request #2897 from ZedThree/silence-ncgen-warnings
Browse files Browse the repository at this point in the history
Fix warnings in `ncgen`
  • Loading branch information
WardF authored Apr 24, 2024
2 parents 73b9f18 + e19558c commit be9cb7f
Show file tree
Hide file tree
Showing 29 changed files with 286 additions and 322 deletions.
26 changes: 12 additions & 14 deletions ncgen/bindata.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifdef ENABLE_BINARY

/* Forward */
static void alignto(int alignment, Bytebuffer* buf, ptrdiff_t base);
static void alignto(size_t alignment, Bytebuffer* buf, size_t base);

static int bin_uid = 0;

Expand Down Expand Up @@ -105,17 +105,17 @@ bin_listbegin(Generator* generator, Symbol* tsym, void* liststate, ListClass lc,
{
if(uidp) *uidp = ++bin_uid;
if(lc == LISTCOMPOUND)
*((int*)liststate) = bbLength(buf);
*((size_t*)liststate) = bbLength(buf);
return 1;
}

static int
bin_list(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, int uid, size_t count, Bytebuffer* buf, ...)
{
if(lc == LISTCOMPOUND) {
int offsetbase = *((int*)liststate);
size_t offsetbase = *((size_t*)liststate);
/* Pad for the alignment */
alignto(tsym->typ.alignment,buf,offsetbase);
alignto(tsym->typ.alignment,buf,offsetbase);
}
return 1;
}
Expand All @@ -124,7 +124,7 @@ static int
bin_listend(Generator* generator, Symbol* tsym, void* liststate, ListClass lc, int uid, size_t count, Bytebuffer* buf, ...)
{
if(lc == LISTCOMPOUND) {
int offsetbase = *((int*)liststate);
size_t offsetbase = *((size_t*)liststate);
/* Pad out the whole instance */
alignto(tsym->typ.cmpdalign,buf,offsetbase);
}
Expand Down Expand Up @@ -167,12 +167,11 @@ static const char zeros[] =
"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";

static void
alignto(int alignment, Bytebuffer* buf, ptrdiff_t base)
alignto(size_t alignment, Bytebuffer* buf, size_t base)
{
int pad = 0;
ptrdiff_t offset = bbLength(buf);
offset -= base; /* Need to actually align wrt to the base */
pad = getpadding(offset,alignment);
/* Need to actually align wrt to the base */
size_t offset = bbLength(buf) - base;
size_t pad = getpadding(offset,alignment);
if(pad > 0) {
bbAppendn(buf,(void*)zeros,pad);
}
Expand All @@ -196,11 +195,10 @@ Generator* bin_generator = &bin_generator_singleton;
static int bin_generate_data_r(NCConstant* instance, Symbol* tsym, Datalist* fillvalue, Bytebuffer* databuf);

static void
write_alignment(int alignment, Bytebuffer* buf)
write_alignment(size_t alignment, Bytebuffer* buf)
{
int pad = 0;
ptrdiff_t offset = bbLength(buf);
pad = getpadding(offset,alignment);
unsigned int offset = bbLength(buf);
size_t pad = getpadding(offset,alignment);
if(pad > 0) {
bbAppendn(buf,(void*)zeros,pad);
}
Expand Down
11 changes: 6 additions & 5 deletions ncgen/bytebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
See the COPYRIGHT file for more information. */

#include "config.h"
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Expand All @@ -22,7 +23,7 @@
int bbdebug = 1;

/* For debugging purposes*/
static long
static int
bbFail(void)
{
fflush(stdout);
Expand Down Expand Up @@ -144,14 +145,14 @@ bbCatbuf(Bytebuffer* bb, const Bytebuffer* s)
}

int
bbAppendn(Bytebuffer* bb, const void* elem, const unsigned int n0)
bbAppendn(Bytebuffer* bb, const void* elem, const size_t n0)
{
unsigned int n = n0;
size_t n = n0;
if(bb == NULL || elem == NULL) return bbFail();
if(n == 0) {n = strlen((char*)elem);}
while(!bbNeed(bb,(n+1))) {if(!bbSetalloc(bb,0)) return bbFail();}
memcpy((void*)&bb->content[bb->length],(void*)elem,n);
bb->length += n;
bb->length += (unsigned int)n;
bb->content[bb->length] = '\0';
return TRUE;
}
Expand All @@ -168,7 +169,7 @@ int
bbInsertn(Bytebuffer* bb, const unsigned int index, const char* elem, const unsigned int n)
{
unsigned int i;
int j;
unsigned int j;
unsigned int newlen = 0;

if(bb == NULL) return bbFail();
Expand Down
3 changes: 2 additions & 1 deletion ncgen/bytebuffer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* Copyright 2018, UCAR/Unidata and OPeNDAP, Inc.
See the COPYRIGHT file for more information. */

#include <stddef.h>
#ifndef BYTEBUFFER_H
#define BYTEBUFFER_H 1

Expand Down Expand Up @@ -33,7 +34,7 @@ EXTERNC int bbGet(Bytebuffer*,unsigned int);
EXTERNC int bbSet(Bytebuffer*,unsigned int,char);

EXTERNC int bbAppend(Bytebuffer*,const char); /* Add at Tail */
EXTERNC int bbAppendn(Bytebuffer*,const void*,unsigned int); /* Add at Tail */
EXTERNC int bbAppendn(Bytebuffer*, const void*, size_t); /* Add at Tail */

/* Insert 1 or more characters at given location */
EXTERNC int bbInsert(Bytebuffer*,const unsigned int,const char);
Expand Down
2 changes: 1 addition & 1 deletion ncgen/cdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ c_constant(Generator* generator, Symbol* sym, NCConstant* con, Bytebuffer* buf,.
} break;
case NC_OPAQUE: {
char* p;
size_t bslen = (size_t)(4*con->value.opaquev.len);
size_t bslen = 4*con->value.opaquev.len;
special = poolalloc(bslen+2+1);
strcpy(special,"\"");
p = con->value.opaquev.stringv;
Expand Down
12 changes: 6 additions & 6 deletions ncgen/cvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "bytebuffer.h"
#include "isnan.h"
#include <math.h>
#include <stddef.h>


#ifndef nulldup
Expand Down Expand Up @@ -71,7 +72,7 @@ case CASE(NC_CHAR,NC_CHAR):
tmp.charv = src->value.charv;
break;
case CASE(NC_CHAR,NC_BYTE):
tmp.int8v = (unsigned char)src->value.charv;
tmp.int8v = (signed char)src->value.charv;
break;
case CASE(NC_CHAR,NC_UBYTE):
tmp.uint8v = (unsigned char)src->value.charv;
Expand Down Expand Up @@ -559,8 +560,8 @@ case CASE(NC_OPAQUE,NC_DOUBLE):
tmp.doublev = *(double*)bytes;
break;
case CASE(NC_OPAQUE,NC_OPAQUE):
tmp.opaquev.stringv = (char*)ecalloc((size_t)src->value.opaquev.len+1);
memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv, (size_t)src->value.opaquev.len);
tmp.opaquev.stringv = (char*)ecalloc(src->value.opaquev.len+1);
memcpy(tmp.opaquev.stringv,src->value.opaquev.stringv, src->value.opaquev.len);
tmp.opaquev.len = src->value.opaquev.len;
tmp.opaquev.stringv[tmp.opaquev.len] = '\0';
break;
Expand Down Expand Up @@ -636,11 +637,10 @@ convertstringtochars(NCConstant* str)
{
int i;
Datalist* dl;
int slen;
char* s;

slen = str->value.stringv.len;
dl = builddatalist(slen);
size_t slen = str->value.stringv.len;
dl = builddatalist((int)slen);
s = str->value.stringv.stringv;
for(i=0;i<slen;i++) {
NCConstant con;
Expand Down
41 changes: 19 additions & 22 deletions ncgen/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ cloneconstant(NCConstant* con)
newcon->value.stringv.stringv = s;
break;
case NC_OPAQUE:
s = (char*)ecalloc((size_t)newcon->value.opaquev.len+1);
s = (char*)ecalloc(newcon->value.opaquev.len+1);
if(newcon->value.opaquev.len > 0)
memcpy(s,newcon->value.opaquev.stringv, (size_t)newcon->value.opaquev.len);
memcpy(s,newcon->value.opaquev.stringv, newcon->value.opaquev.len);
s[newcon->value.opaquev.len] = '\0';
newcon->value.opaquev.stringv = s;
break;
Expand Down Expand Up @@ -219,7 +219,7 @@ datalistline(Datalist* ds)
*/

static char* commifyr(char* p, Bytebuffer* buf);
static char* wordstring(char* p, Bytebuffer* buf, int quote);
static char* wordstring(char* p, Bytebuffer* buf, char quote);

void
commify(Bytebuffer* buf)
Expand All @@ -242,7 +242,7 @@ static char*
commifyr(char* p, Bytebuffer* buf)
{
int comma = 0;
int c;
char c;
while((c=*p++)) {
if(c == ' ') continue;
if(c == ',') continue;
Expand All @@ -267,24 +267,24 @@ commifyr(char* p, Bytebuffer* buf)
char*
word(char* p, Bytebuffer* buf)
{
int c;
char c;
while((c=*p++)) {
if(c == '}' || c == ' ' || c == ',') break;
if(c == '\\') {
bbAppend(buf,c);
c=*p++;
if(!c) break;
}
bbAppend(buf,(char)c);
bbAppend(buf, c);
}
p--; /* leave terminator for parent */
return p;
}

static char*
wordstring(char* p, Bytebuffer* buf, int quote)
wordstring(char* p, Bytebuffer* buf, char quote)
{
int c;
char c;
bbAppend(buf,quote);
while((c=*p++)) {
if(c == '\\') {
Expand All @@ -309,7 +309,7 @@ alignbuffer(NCConstant* prim, Bytebuffer* buf)
{
int stat = NC_NOERR;
size_t alignment;
int pad,offset;
size_t pad,offset;

ASSERT(prim->nctype != NC_COMPOUND);

Expand Down Expand Up @@ -392,7 +392,7 @@ vbbprintf(Bytebuffer* buf, const char* fmt, va_list argv)
{
char tmp[128];
const char* p;
int c;
char c;
int hcount;
int lcount;

Expand Down Expand Up @@ -481,8 +481,8 @@ retry: switch ((c=*p++)) {
bbCat(buf,text);
break;
case 'c':
c = va_arg(argv,int);
bbAppend(buf,(char)c);
c = (char)va_arg(argv,int);
bbAppend(buf,c);
break;
default:
PANIC1("vbbprintf: unknown specifier: %c",(char)c);
Expand Down Expand Up @@ -629,11 +629,10 @@ dlset(Datalist* dl, size_t pos, NCConstant* constant)
NCConstant*
dlremove(Datalist* dl, size_t pos)
{
int i;
NCConstant* con = NULL;
ASSERT(dl->length > 0 && pos < dl->length);
con = dl->data[pos];
for(i=pos+1;i<dl->length;i++)
for(size_t i=pos+1;i<dl->length;i++)
dl->data[i-1] = dl->data[i];
dl->length--;
return con;
Expand All @@ -642,18 +641,17 @@ dlremove(Datalist* dl, size_t pos)
void
dlinsert(Datalist* dl, size_t pos, Datalist* insertion)
{
int i;
int len1 = datalistlen(dl);
int len2 = datalistlen(insertion);
int delta = len1 - pos;
size_t len1 = datalistlen(dl);
size_t len2 = datalistlen(insertion);
ptrdiff_t delta = (ptrdiff_t)(len1 - pos);
dlsetalloc(dl, len2+len1+1);


/* move contents of dl up to make room for insertion */
if(delta > 0)
memmove(&dl->data[pos+len2],&dl->data[pos], (size_t)delta*sizeof(NCConstant*));
dl->length += len2;
for(i=0;i<len2;i++) {
for(size_t i=0;i<len2;i++) {
NCConstant* con = insertion->data[i];
con = cloneconstant(con);
dl->data[pos+i] = con;
Expand Down Expand Up @@ -701,7 +699,7 @@ clonedatalist(Datalist* dl)

if(dl == NULL) return NULL;
len = datalistlen(dl);
newdl = builddatalist(len);
newdl = builddatalist((int)len);
/* initialize */
for(i=0;i<len;i++) {
NCConstant* con = datalistith(dl,i);
Expand Down Expand Up @@ -776,8 +774,7 @@ freedatalist(Datalist* list)
void
reclaimalldatalists(void)
{
int i;
for(i=0;i<listlength(alldatalists);i++) {
for(size_t i=0;i<listlength(alldatalists);i++) {
Datalist* di = listget(alldatalists,i);
if(di != NULL)
reclaimdatalist(di);
Expand Down
7 changes: 4 additions & 3 deletions ncgen/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* See netcdf/COPYRIGHT file for copying and redistribution conditions.
*********************************************************************/

#include <stddef.h>
#ifndef DATA_H
#define DATA_H 1

Expand Down Expand Up @@ -36,11 +37,11 @@ typedef union Constvalue {
float floatv; /* NC_FLOAT*/
double doublev; /* NC_DOUBLE*/
struct Stringv { /* NC_STRING*/
int len;
char* stringv;
size_t len;
char* stringv;
} stringv;
struct Opaquev { /* NC_OPAQUE*/
int len; /* length as originally written (rounded to even number)*/
size_t len; /* length as originally written (rounded to even number)*/
char* stringv; /*as constant was written*/
/* (padded to even # chars >= 16)*/
/* without leading 0x*/
Expand Down
14 changes: 2 additions & 12 deletions ncgen/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
/* $Header: /upc/share/CVS/netcdf-3/ncgen/dump.c,v 1.3 2010/05/24 19:59:57 dmh Exp $ */

#include "includes.h"
#include <stddef.h>
#include "dump.h"

#undef DEBUGSRC
Expand All @@ -16,16 +17,6 @@
/* Forward */
static void dumpdataprim(NCConstant*,Bytebuffer*);

char*
indentstr(int n)
{
static char indentline[1024];
memset(indentline,' ',n+1);
indentline[n+1] = '\0';
return indentline;
}


void
dumpconstant(NCConstant* con, char* tag)
{
Expand All @@ -51,14 +42,13 @@ bufdump(Datalist* list, Bytebuffer* buf)
{
int i;
NCConstant** dpl;
unsigned int count;

if(list == NULL) {
bbCat(buf,"NULL");
return;
}

count = list->length;
size_t count = list->length;
for(dpl=list->data,i=0;i<count;i++,dpl++) {
NCConstant* dp = *dpl;
switch (dp->nctype) {
Expand Down
Loading

0 comments on commit be9cb7f

Please sign in to comment.