Mesa (master): util: Fix UBSan failure on _mesa_unorm_to_unorm.
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Fri Jan 15 19:15:28 UTC 2021
Module: Mesa
Branch: master
Commit: 05652703807758cb48a09cb6bbd29bacb0dfa870
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=05652703807758cb48a09cb6bbd29bacb0dfa870
Author: Eric Anholt <eric at anholt.net>
Date: Wed Aug 12 14:30:18 2020 -0700
util: Fix UBSan failure on _mesa_unorm_to_unorm.
It complains about shifting 1<<31 being undefined, so make it a 1u.
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Acked-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6297>
---
src/util/format/format_utils.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/format/format_utils.h b/src/util/format/format_utils.h
index e752bf2563a..fa1d30060d9 100644
--- a/src/util/format/format_utils.h
+++ b/src/util/format/format_utils.h
@@ -94,7 +94,7 @@ _mesa_unorm_to_unorm(unsigned x, unsigned src_bits, unsigned dst_bits)
if (src_bits < dst_bits) {
return EXTEND_NORMALIZED_INT(x, src_bits, dst_bits);
} else if (src_bits > dst_bits) {
- unsigned src_half = (1 << (src_bits - 1)) - 1;
+ unsigned src_half = (1u << (src_bits - 1)) - 1;
if (src_bits + dst_bits > sizeof(x) * 8) {
assert(src_bits + dst_bits <= sizeof(uint64_t) * 8);
More information about the mesa-commit
mailing list