Change type of opaque object length member

This commit is contained in:
Peter Hill 2023-12-11 13:41:17 +00:00
parent 6b17d77e7a
commit 17a7b28301
No known key found for this signature in database
GPG Key ID: 0C6B9742E72848EE
6 changed files with 10 additions and 11 deletions

View File

@ -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;

View File

@ -560,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;

View File

@ -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;

View File

@ -41,7 +41,7 @@ typedef union Constvalue {
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*/

View File

@ -259,16 +259,16 @@ normalizeopaquelength(NCConstant* prim, unsigned long nbytes)
/* do nothing*/
} else if(prim->value.opaquev.len > nnibs) { /* truncate*/
prim->value.opaquev.stringv[nnibs] = '\0';
prim->value.opaquev.len = (int)nnibs;
prim->value.opaquev.len = nnibs;
} else {/* prim->value.opaquev.len < nnibs => expand*/
char* s;
s = (char*)ecalloc(nnibs+1);
memset(s,'0',nnibs); /* Fill with '0' characters */
memcpy(s,prim->value.opaquev.stringv, (size_t)prim->value.opaquev.len);
memcpy(s,prim->value.opaquev.stringv, prim->value.opaquev.len);
s[nnibs] = '\0';
efree(prim->value.opaquev.stringv);
prim->value.opaquev.stringv=s;
prim->value.opaquev.len = (int)nnibs;
prim->value.opaquev.len = nnibs;
}
}

View File

@ -3318,8 +3318,7 @@ makeconstdata(nc_type nctype)
#ifdef USE_NETCDF4
case NC_OPAQUE: {
char* s;
size_t len;
len = bbLength(lextext);
size_t len = bbLength(lextext);
s = (char*)ecalloc(len+1);
strncpy(s,bbContents(lextext),len);
s[len] = '\0';