From 4542204b3ab2f1cc4cc019d77531761abce540ef Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 25 Nov 2015 18:28:25 -0800 Subject: [PATCH] Fix undefined behavior in DataBlockCache::SetBlockCount() Left-shifting negative signed numbers is UB (and pointlessly complex here anyway). --- src/block_cache.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/block_cache.h b/src/block_cache.h index fd84f86f6..35ad0eedd 100644 --- a/src/block_cache.h +++ b/src/block_cache.h @@ -119,9 +119,8 @@ public: if (data.size() > 0) Age(0); - macroblock_size = 1 << MacroblockExponent; - - macroblock_index_mask = ~(((~0) >> MacroblockExponent) << MacroblockExponent); + macroblock_size = 1UL << MacroblockExponent; + macroblock_index_mask = macroblock_size - 1; data.resize((block_count + macroblock_size - 1) >> MacroblockExponent); size = 0;