Mesa (main): pan/decode: Avoid undefined behaviour on shift in bits()
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jul 14 23:39:02 UTC 2021
Module: Mesa
Branch: main
Commit: 04c02418d74703812a39405df14e130c2d6fd098
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=04c02418d74703812a39405df14e130c2d6fd098
Author: Icecream95 <ixn at disroot.org>
Date: Wed Jul 14 12:47:30 2021 +1200
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>
---
src/panfrost/lib/decode.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/src/panfrost/lib/decode.c b/src/panfrost/lib/decode.c
index 07366e45072..7a67121a91b 100644
--- a/src/panfrost/lib/decode.c
+++ b/src/panfrost/lib/decode.c
@@ -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);
}
More information about the mesa-commit
mailing list