Reported by Coverity (CID 50925):
Unintentional integer overflow (OVERFLOW_BEFORE_WIDEN)
overflow_before_widen: Potentially overflowing expression 1 << power
with type int (32 bits, signed) is evaluated using 32-bit arithmetic,
and then used in a context that expects an expression of type
uint64_t const (64 bits, unsigned).
#include <cmath>
#include <cstdlib>
#include <cstring>
+#include <cstdint>
#include "logic.hpp"
#include "logicsegment.hpp"
uint64_t LogicSegment::pow2_ceil(uint64_t x, unsigned int power)
{
- const uint64_t p = 1 << power;
+ const uint64_t p = UINT64_C(1) << power;
return (x + p - 1) / p * p;
}