From 97b001e7c0108ebe474494acba5a331aac4dedb3 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 24 Jan 2021 15:22:14 +0100 Subject: [PATCH] Fix undefined left shift Small unsigned integers promote to signed int. As a consequence, if v is a uint8_t, then (v << 24) yields an int, so the left shift is undefined if the MSB is 1. Cast to uint32_t to yield an unsigned value. Reported by USAN (meson x -Db_sanitize=undefined): runtime error: left shift of 255 by 24 places cannot be represented in type 'int' --- app/src/util/buffer_util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/util/buffer_util.h b/app/src/util/buffer_util.h index ab22ab24..337bb262 100644 --- a/app/src/util/buffer_util.h +++ b/app/src/util/buffer_util.h @@ -33,7 +33,7 @@ buffer_read16be(const uint8_t *buf) { static inline uint32_t buffer_read32be(const uint8_t *buf) { - return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; + return ((uint32_t) buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; } static inline uint64_t