Commit 73f88592 authored by Tavian Barnes's avatar Tavian Barnes Committed by Kent Overstreet

bcachefs: mean_and_variance: Avoid too-large shift amounts

Shifting a value by the width of its type or more is undefined.
Signed-off-by: default avatarTavian Barnes <tavianator@tavianator.com>
Signed-off-by: default avatarKent Overstreet <kent.overstreet@linux.dev>
parent a97b43fa
...@@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift) ...@@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift)
{ {
u128_u r; u128_u r;
r.lo = i.lo << shift; r.lo = i.lo << (shift & 63);
if (shift < 64) if (shift < 64)
r.hi = (i.hi << shift) | (i.lo >> (64 - shift)); r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63));
else { else {
r.hi = i.lo << (shift - 64); r.hi = i.lo << (-shift & 63);
r.lo = 0; r.lo = 0;
} }
return r; return r;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment