Skip to content

Commit eac6a30

Browse files
committed
refactor: Rework asmap Interpret to avoid ptrdiff_t
1 parent df37377 commit eac6a30

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/util/asmap.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ uint32_t Interpret(const std::vector<bool> &asmap, const std::vector<bool> &ip)
9393
jump = DecodeJump(pos, endpos);
9494
if (jump == INVALID) break; // Jump offset straddles EOF
9595
if (bits == 0) break; // No input bits left
96-
if (jump >= endpos - pos) break; // Jumping past EOF
96+
if (pos + jump < pos) break; // overflow
97+
if (pos + jump >= endpos) break; // Jumping past EOF
9798
if (ip[ip.size() - bits]) {
9899
pos += jump;
99100
}
@@ -155,7 +156,8 @@ bool SanityCheckASMap(const std::vector<bool>& asmap, int bits)
155156
} else if (opcode == Instruction::JUMP) {
156157
uint32_t jump = DecodeJump(pos, endpos);
157158
if (jump == INVALID) return false; // Jump offset straddles EOF
158-
if (jump > endpos - pos) return false; // Jump out of range
159+
if (pos + jump < pos) return false; // overflow
160+
if (pos + jump > endpos) return false; // Jump out of range
159161
if (bits == 0) return false; // Consuming bits past the end of the input
160162
--bits;
161163
uint32_t jump_offset = pos - begin + jump;

0 commit comments

Comments
 (0)