Mesa (main): freedreno: Fix UBSan failures in cffdec's (uint8_t)x << 24

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Oct 1 23:38:26 UTC 2021


Module: Mesa
Branch: main
Commit: 21df8b3e08766a4e4f919241a5c3aadd48239ba0
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=21df8b3e08766a4e4f919241a5c3aadd48239ba0

Author: Eric Anholt <eric at anholt.net>
Date:   Mon Aug 17 13:56:38 2020 -0700

freedreno: Fix UBSan failures in cffdec's (uint8_t)x << 24

Types <32 bit get promoted to int32_t when you do expressions on them
(thus why (u8)x << 8 works at all), but shifting into the top bit of the
signed int is undefined behavior.

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

---

 src/freedreno/decode/util.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/freedreno/decode/util.h b/src/freedreno/decode/util.h
index 497f5615000..21655c80902 100644
--- a/src/freedreno/decode/util.h
+++ b/src/freedreno/decode/util.h
@@ -68,7 +68,7 @@ dump_hex(const void *buf, int sz)
       d |= *(ptr++) << 0;
       d |= *(ptr++) << 8;
       d |= *(ptr++) << 16;
-      d |= *(ptr++) << 24;
+      d |= (uint32_t)*(ptr++) << 24;
 
       printf("%08x", d);
 
@@ -99,7 +99,7 @@ dump_float(const void *buf, int sz)
       d |= *(ptr++) << 0;
       d |= *(ptr++) << 8;
       d |= *(ptr++) << 16;
-      d |= *(ptr++) << 24;
+      d |= (uint32_t)*(ptr++) << 24;
 
       printf("%8f", d2f(d));
 
@@ -171,7 +171,7 @@ dump_hex_ascii(const void *buf, int sz, int level)
       d |= *(ptr++) << 0;
       d |= *(ptr++) << 8;
       d |= *(ptr++) << 16;
-      d |= *(ptr++) << 24;
+      d |= (uint32_t)*(ptr++) << 24;
 
       printf("%08x", d);
 



More information about the mesa-commit mailing list