From f98cd10485ce0873dfcb4f483a9e579aea474982 Mon Sep 17 00:00:00 2001 From: tosh Date: Wed, 27 Mar 2013 15:47:39 +0100 Subject: [PATCH] straightens potential range issues for wide integers --- shared/src/Radix2IntegerScanner.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/shared/src/Radix2IntegerScanner.h b/shared/src/Radix2IntegerScanner.h index 32cc03d1e7..354cec65e2 100644 --- a/shared/src/Radix2IntegerScanner.h +++ b/shared/src/Radix2IntegerScanner.h @@ -47,7 +47,9 @@ class Radix2IntegerScanner< UInt, false > Radix2IntegerScanner() : msb(~UInt(0) &~ (~UInt(0) >> 1)) { } - explicit Radix2IntegerScanner(int bits) : msb(1u << (bits - 1)) { } + explicit Radix2IntegerScanner(int bits) + : msb(UInt(1u) << (bits - 1)) + { } typedef UInt state_type; @@ -65,9 +67,12 @@ class Radix2IntegerScanner< Int, true > public: Radix2IntegerScanner() - : msb(~state_type(0) &~ (~state_type(0) >> 1)) { } + : msb(~state_type(0u) &~ (~state_type(0u) >> 1)) + { } - explicit Radix2IntegerScanner(int bits) : msb(1u << (bits - 1)) { } + explicit Radix2IntegerScanner(int bits) + : msb(state_type(1u) << (bits - 1)) + { } typedef typename type_traits::make_unsigned::type state_type; @@ -75,7 +80,8 @@ class Radix2IntegerScanner< Int, true > state_type initial_state() const { return msb; } bool advance(state_type& s) const { return (s >>= 1) != 0u; } - bool bit(Int const& v, state_type const& s) const { return !!((v-msb) & s); } + bool bit(Int const& v, state_type const& s) const + { return !!((v-msb) & s); } }; #endif /* defined(__hifi__Radix2IntegerScanner__) */