mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-03-31 17:50:26 +08:00
Change type of opaque object length member
This commit is contained in:
parent
6b17d77e7a
commit
17a7b28301
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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*/
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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';
|
||||
|
Loading…
x
Reference in New Issue
Block a user