From: Tavian Barnes Date: Fri, 21 Jun 2024 20:39:58 +0000 (-0400) Subject: bcachefs: varint: Avoid left-shift of a negative value X-Git-Tag: v6.11-rc1~120^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ee1b8dc17ac367f3fbea18fee4f7825eb11eb757;p=thirdparty%2Fkernel%2Flinux.git bcachefs: varint: Avoid left-shift of a negative value Shifting a negative value left is undefined. Signed-off-by: Tavian Barnes Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/varint.c b/fs/bcachefs/varint.c index cb4f33ed9ab37..a9ebcd82c6025 100644 --- a/fs/bcachefs/varint.c +++ b/fs/bcachefs/varint.c @@ -85,7 +85,7 @@ int bch2_varint_encode_fast(u8 *out, u64 v) if (likely(bytes < 9)) { v <<= bytes; - v |= ~(~0 << (bytes - 1)); + v |= ~(~0U << (bytes - 1)); } else { *out++ = 255; bytes = 9;