pan/decode: Avoid undefined behaviour on shift in bits()

v2: Return 0 instead of `word` (Alyssa)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11869>
This commit is contained in:
Icecream95 2021-07-14 12:47:30 +12:00 committed by Marge Bot
parent 6642749458
commit 04c02418d7
1 changed files with 3 additions and 0 deletions

View 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);
}