From 0b51752974099bb5fa0725a4a7b21a80a22768f3 Mon Sep 17 00:00:00 2001 From: Havard Eidnes Date: Wed, 24 May 2023 23:03:44 +0000 Subject: [PATCH] ArenaAlloc/arenaallocimpl.h: avoid shift overflow on 32-bit hosts. Use the constants defined by to avoid right-shift by 32 on a 32-bit host by comparing SIZE_MAX to UINT32_MAX, since `value` is a size_t. Found by building on NetBSD/macppc with -Wshift-count-overflow (which is default on in the pkgsrc setup, which this is from). ./third-party/ArenaAlloc/arenaallocimpl.h:111:22: warning: right shift count >= width of type [-Wshift-count-overflow] 111 | value |= value >> 32; | ~~~~~~^~~~~ --- src/third-party/ArenaAlloc/arenaallocimpl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/third-party/ArenaAlloc/arenaallocimpl.h b/src/third-party/ArenaAlloc/arenaallocimpl.h index 12484f01..879e0d27 100644 --- a/src/third-party/ArenaAlloc/arenaallocimpl.h +++ b/src/third-party/ArenaAlloc/arenaallocimpl.h @@ -13,6 +13,8 @@ #include #endif +#include + namespace ArenaAlloc { @@ -108,7 +110,9 @@ namespace ArenaAlloc value |= value >> 4; value |= value >> 8; value |= value >> 16; +#if SIZE_MAX > UINT32_MAX value |= value >> 32; +#endif return value + 1; }