# HG changeset patch # User alberth # Date 2010-09-22 20:59:24 # Node ID 0ba842e17bf191567df32ca9273ac570191e66c3 # Parent 83ffcbc14970f4500bf01f7c60b4c4a65f3e3a6d (svn r20838) -Fix [FS#4136]: Cast '1' in bitmath functions to width of result before shifting. diff --git a/src/core/bitmath_func.hpp b/src/core/bitmath_func.hpp --- a/src/core/bitmath_func.hpp +++ b/src/core/bitmath_func.hpp @@ -31,7 +31,7 @@ template static FORCEINLINE uint GB(const T x, const uint8 s, const uint8 n) { - return (x >> s) & ((1U << n) - 1); + return (x >> s) & (((T)1U << n) - 1); } /** @@ -55,7 +55,7 @@ static FORCEINLINE uint GB(const T x, co template static FORCEINLINE T SB(T &x, const uint8 s, const uint8 n, const U d) { - x &= (T)(~(((1U << n) - 1) << s)); + x &= (T)(~((((T)1U << n) - 1) << s)); x |= (T)(d << s); return x; } @@ -78,7 +78,7 @@ static FORCEINLINE T SB(T &x, const uint template static FORCEINLINE T AB(T &x, const uint8 s, const uint8 n, const U i) { - const T mask = (T)(((1U << n) - 1) << s); + const T mask = ((((T)1U << n) - 1) << s); x = (T)((x & ~mask) | ((x + (i << s)) & mask)); return x; } @@ -114,7 +114,7 @@ static FORCEINLINE bool HasBit(const T x template static FORCEINLINE T SetBit(T &x, const uint8 y) { - return x = (T)(x | (T)(1U << y)); + return x = (T)(x | ((T)1U << y)); } /** @@ -172,7 +172,7 @@ static FORCEINLINE T ClrBit(T &x, const template static FORCEINLINE T ToggleBit(T &x, const uint8 y) { - return x = (T)(x ^ (T)(1U << y)); + return x = (T)(x ^ ((T)1U << y)); }