From 3123340d5ffb471df6b045fbdaf97fa427f21834 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 18:05:12 +0700 Subject: [PATCH] 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 --- common/parity.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/common/parity.h b/common/parity.h index 3985a1e04..2fa4b8904 100644 --- a/common/parity.h +++ b/common/parity.h @@ -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