diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-04-29 08:50:06 +0200 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-04-29 11:38:18 +0200 |
commit | fa098713201a6999ec4c12d0a8bde0adcf47b095 (patch) | |
tree | e51748dbf633ef088405fea20c9100a8d67adc27 /src/util/asmap.cpp | |
parent | fb66dbe786ff3028d8f2b0be503ddd3b36541798 (diff) |
refactor: Avoid sign-compare compiler warning in util/asmap
This reverts commit eac6a3080d38cfd4eb7204ecd327df213958e51a ("refactor:
Rework asmap Interpret to avoid ptrdiff_t"), because it is UB to form a
past-the-end iterator, even if it is never dereferenced.
Then fix the compiler warning in a different way:
Instead of comparing an uint32_t against a signed ptrdiff_t, just
promote both to a type that can represent both types.
Even though in this case the ptrdiff_t should never hold a negative
value, the overhead from promotion should be negligible.
Diffstat (limited to 'src/util/asmap.cpp')
-rw-r--r-- | src/util/asmap.cpp | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp index bd77d74218..bacc3690a2 100644 --- a/src/util/asmap.cpp +++ b/src/util/asmap.cpp @@ -93,8 +93,7 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip) jump = DecodeJump(pos, endpos); if (jump == INVALID) break; // Jump offset straddles EOF if (bits == 0) break; // No input bits left - if (pos + jump < pos) break; // overflow - if (pos + jump >= endpos) break; // Jumping past EOF + if (int64_t{jump} >= int64_t{endpos - pos}) break; // Jumping past EOF if (ip[ip.size() - bits]) { pos += jump; } @@ -156,8 +155,7 @@ bool SanityCheckASMap(const std::vector<bool>& asmap, int bits) } else if (opcode == Instruction::JUMP) { uint32_t jump = DecodeJump(pos, endpos); if (jump == INVALID) return false; // Jump offset straddles EOF - if (pos + jump < pos) return false; // overflow - if (pos + jump > endpos) return false; // Jump out of range + if (int64_t{jump} > int64_t{endpos - pos}) return false; // Jump out of range if (bits == 0) return false; // Consuming bits past the end of the input --bits; uint32_t jump_offset = pos - begin + jump; |