mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-18 15:55:12 +08:00
fix the setting of the member len of NC_var object, related to issue 463
This commit is contained in:
parent
fde8720fd3
commit
8c5956946a
@ -309,8 +309,7 @@ fprintf(stderr, " REC %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index);
|
||||
return NC_EVARSIZE;
|
||||
}
|
||||
#endif
|
||||
if((*vpp)->len != UINT32_MAX) /* flag for vars >= 2**32 bytes */
|
||||
ncp->recsize += (*vpp)->len;
|
||||
ncp->recsize += (*vpp)->len;
|
||||
last = (*vpp);
|
||||
}
|
||||
|
||||
|
34
libsrc/var.c
34
libsrc/var.c
@ -484,29 +484,17 @@ NC_var_shape(NC_var *varp, const NC_dimarray *dims)
|
||||
|
||||
|
||||
out :
|
||||
if( varp->xsz <= (X_UINT_MAX - 1) / product ) /* if integer multiply will not overflow */
|
||||
{
|
||||
varp->len = product * varp->xsz;
|
||||
switch(varp->type) {
|
||||
case NC_BYTE :
|
||||
case NC_CHAR :
|
||||
case NC_UBYTE :
|
||||
case NC_SHORT :
|
||||
case NC_USHORT :
|
||||
if( varp->len%4 != 0 )
|
||||
{
|
||||
varp->len += 4 - varp->len%4; /* round up */
|
||||
/* *dsp += 4 - *dsp%4; */
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* already aligned */
|
||||
break;
|
||||
}
|
||||
} else
|
||||
{ /* OK for last var to be "too big", indicated by this special len */
|
||||
varp->len = X_UINT_MAX;
|
||||
}
|
||||
/*
|
||||
* For CDF-1 and CDF-2 formats, the total number of array elements
|
||||
* cannot exceed 2^32, unless this variable is the last fixed-size
|
||||
* variable, there is no record variable, and the file starting
|
||||
* offset of this variable is less than 2GiB.
|
||||
* This will be checked in NC_check_vlens() during NC_endef()
|
||||
*/
|
||||
varp->len = product * varp->xsz;
|
||||
if (varp->len % 4 > 0)
|
||||
varp->len += 4 - varp->len % 4; /* round up */
|
||||
|
||||
#if 0
|
||||
arrayp("\tshape", varp->ndims, varp->shape);
|
||||
arrayp("\tdsizes", varp->ndims, varp->dsizes);
|
||||
|
Loading…
Reference in New Issue
Block a user