mirror of https://github.com/ecmwf/eccodes.git
bits: grib_encode_unsigned_long: increment pointer, not the pointed-to-value
This fixes a long-standing (i.e. at least since 1.9.5 ca. Oct 2010) bug in grib_encode_unsigned_long where the first byte was incorrectly incremented instead of incrementing the pointer to the next byte. This would only happen if the bit position / offset was not aligned on a byte boundary (i.e. *bitp % 8 != 0), though. Fortunately, as far as I can tell, no grib_api/eccodes functions invoked grib_encode_unsigned_long such that this bug was manifested. * src/grib_bits_any_endian.c: increment pointer, not the pointed-to-value * src/grib_bits_ibmpow.c: likewise.
This commit is contained in:
parent
a5a87cc4b7
commit
c950c6f968
|
@ -280,12 +280,7 @@ int grib_encode_unsigned_long(unsigned char* p, unsigned long val, long* bitp, l
|
|||
else {
|
||||
tmp = ((val >> len) | ((*p) & dmasks[n]));
|
||||
}
|
||||
*p = tmp;
|
||||
(*p)++;
|
||||
|
||||
/*Beware of code like this! compiler warning: operation may be undefined
|
||||
Read GCC manual on -Wsequence-point*/
|
||||
/* *p = ((val << -len) | ((*p)++ & dmasks[n])); */
|
||||
*p++ = tmp;
|
||||
}
|
||||
|
||||
/* write the middle words */
|
||||
|
|
|
@ -107,8 +107,7 @@ int grib_encode_unsigned_long(unsigned char* p, unsigned long val, long* bitp, l
|
|||
else {
|
||||
tmp = ((val >> len) | ((*p) & dmasks[n]));
|
||||
}
|
||||
*p = tmp;
|
||||
(*p)++;
|
||||
*p++ = tmp;
|
||||
}
|
||||
|
||||
/* write the middle words */
|
||||
|
|
Loading…
Reference in New Issue