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:
Matthew Krupcale 2020-03-09 19:16:32 -04:00
parent a5a87cc4b7
commit c950c6f968
2 changed files with 2 additions and 8 deletions

View File

@ -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 */

View File

@ -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 */