mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-23 14:45:19 +00:00
btrfs-progs: Fix undefined behavior in radix-tree.c.
When running with UndefinedBehaviorSanitizer, the tests produce the following error: radix-tree.c:836:30: runtime error: shift exponent 18446744073709551613 is too large for 64-bit type 'unsigned long' (That's a negative shift exponent represented as an unsigned long.) Even though the value is discarded in those cases, it's still undefined behavior; see the C99 standard, section 6.5.7, paragraph three: "If the value of the right operand is negative [...] the behavior is undefined." Signed-off-by: Adam Buchbinder <abuchbinder@google.com> Reviewed-by: Satoru Takeuchi <takeuchi_satoru@jp.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
5351d29eef
commit
c9951e2269
@ -833,10 +833,10 @@ int radix_tree_tagged(struct radix_tree_root *root, unsigned int tag)
|
||||
static unsigned long __maxindex(unsigned int height)
|
||||
{
|
||||
unsigned int tmp = height * RADIX_TREE_MAP_SHIFT;
|
||||
unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
|
||||
unsigned long index = ~0UL;
|
||||
|
||||
if (tmp >= RADIX_TREE_INDEX_BITS)
|
||||
index = ~0UL;
|
||||
if (tmp < RADIX_TREE_INDEX_BITS)
|
||||
index = (index >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
|
||||
return index;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user