pan/decode: Avoid undefined behaviour on shift in bits()
authorIcecream95 <ixn@disroot.org>
Wed, 14 Jul 2021 00:47:30 +0000 (12:47 +1200)
committerMarge Bot <eric+marge@anholt.net>
Wed, 14 Jul 2021 23:20:13 +0000 (23:20 +0000)
v2: Return 0 instead of `word` (Alyssa)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11869>

src/panfrost/lib/decode.c

index 07366e4..7a67121 100644 (file)
@@ -451,6 +451,9 @@ bits(u32 word, u32 lo, u32 hi)
         if (hi - lo >= 32)
                 return word; // avoid undefined behavior with the shift
 
+        if (lo >= 32)
+                return 0;
+
         return (word >> lo) & ((1 << (hi - lo)) - 1);
 }