ArenaAlloc/arenaallocimpl.h: avoid shift overflow on 32-bit hosts.

Use the constants defined by <stdint.h> 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;
      |                ~~~~~~^~~~~
This commit is contained in:
Havard Eidnes 2023-05-24 23:03:44 +00:00
parent 34f026e444
commit 0b51752974

View File

@ -13,6 +13,8 @@
#include <stdio.h> #include <stdio.h>
#endif #endif
#include <stdint.h>
namespace ArenaAlloc namespace ArenaAlloc
{ {
@ -108,7 +110,9 @@ namespace ArenaAlloc
value |= value >> 4; value |= value >> 4;
value |= value >> 8; value |= value >> 8;
value |= value >> 16; value |= value >> 16;
#if SIZE_MAX > UINT32_MAX
value |= value >> 32; value |= value >> 32;
#endif
return value + 1; return value + 1;
} }