mirror of
https://github.com/Z3Prover/z3
synced 2026-02-14 21:01:49 +00:00
Fix undefined behavior in SMALL_INT_MAX/MIN constants by using unsigned arithmetic
Co-authored-by: nunoplopes <2998477+nunoplopes@users.noreply.github.com>
This commit is contained in:
parent
d3572a95b9
commit
940910efb6
1 changed files with 3 additions and 2 deletions
|
|
@ -99,8 +99,9 @@ private:
|
|||
static constexpr int SMALL_BITS = sizeof(uintptr_t) * 8 - 1;
|
||||
|
||||
// Maximum and minimum values that can be stored as small integers
|
||||
static constexpr int64_t SMALL_INT_MAX = (static_cast<int64_t>(1) << (SMALL_BITS - 1)) - 1;
|
||||
static constexpr int64_t SMALL_INT_MIN = -(static_cast<int64_t>(1) << (SMALL_BITS - 1));
|
||||
// Use unsigned arithmetic to avoid undefined behavior on left shift
|
||||
static constexpr int64_t SMALL_INT_MAX = (static_cast<uint64_t>(1) << (SMALL_BITS - 1)) - 1;
|
||||
static constexpr int64_t SMALL_INT_MIN = -(static_cast<int64_t>(static_cast<uint64_t>(1) << (SMALL_BITS - 1)));
|
||||
|
||||
static bool fits_in_small(int64_t v) {
|
||||
return v >= SMALL_INT_MIN && v <= SMALL_INT_MAX;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue