From 21df8b3e08766a4e4f919241a5c3aadd48239ba0 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 17 Aug 2020 13:56:38 -0700 Subject: [PATCH] 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: --- 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);