parity: mask table index in non-GNUC fallbacks
The 16/32-bit parity fallbacks folded x but indexed g_odd_byte_parity[256] with the unmasked value, reading out of bounds. Only reachable with a compiler that does not define __GNUC__. Found by cppcheck 2.22. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
00ae94312c
commit
3123340d5f
1 file changed
+4
-4
+4
-4
@@ -56,7 +56,7 @@ static inline uint8_t evenparity8(const uint8_t x) {
|
||||
static inline uint8_t evenparity16(uint16_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 8;
|
||||
return EVEN_PARITY8(x) ;
|
||||
return EVEN_PARITY8(x & 0xFF);
|
||||
#else
|
||||
return __builtin_parity(x);
|
||||
#endif
|
||||
@@ -65,7 +65,7 @@ static inline uint8_t evenparity16(uint16_t x) {
|
||||
static inline uint8_t oddparity16(uint16_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 8;
|
||||
return ODD_PARITY8(x);
|
||||
return ODD_PARITY8(x & 0xFF);
|
||||
#else
|
||||
return !__builtin_parity(x);
|
||||
#endif
|
||||
@@ -75,7 +75,7 @@ static inline uint8_t evenparity32(uint32_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
return EVEN_PARITY8(x) ;
|
||||
return EVEN_PARITY8(x & 0xFF);
|
||||
#else
|
||||
return __builtin_parity(x);
|
||||
#endif
|
||||
@@ -85,7 +85,7 @@ static inline uint8_t oddparity32(uint32_t x) {
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
return ODD_PARITY8(x);
|
||||
return ODD_PARITY8(x & 0xFF);
|
||||
#else
|
||||
return !__builtin_parity(x);
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user