Skip to content

Commit 73f8859

Browse files
tavianatorKent Overstreet
authored andcommitted
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: Tavian Barnes <[email protected]> Signed-off-by: Kent Overstreet <[email protected]>
1 parent a97b43f commit 73f8859

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

fs/bcachefs/mean_and_variance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ static inline u128_u u128_shl(u128_u i, s8 shift)
111111
{
112112
u128_u r;
113113

114-
r.lo = i.lo << shift;
114+
r.lo = i.lo << (shift & 63);
115115
if (shift < 64)
116-
r.hi = (i.hi << shift) | (i.lo >> (64 - shift));
116+
r.hi = (i.hi << (shift & 63)) | (i.lo >> (-shift & 63));
117117
else {
118-
r.hi = i.lo << (shift - 64);
118+
r.hi = i.lo << (-shift & 63);
119119
r.lo = 0;
120120
}
121121
return r;

0 commit comments

Comments
 (0)