Skip to content

Commit

Permalink
refactor: Rework asmap Interpret to avoid ptrdiff_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Empact committed May 9, 2020
1 parent df37377 commit eac6a30
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/asmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ 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 (jump >= endpos - pos) break; // Jumping past EOF
if (pos + jump < pos) break; // overflow
if (pos + jump >= endpos) break; // Jumping past EOF
if (ip[ip.size() - bits]) {
pos += jump;
}
Expand Down Expand Up @@ -155,7 +156,8 @@ 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 (jump > endpos - pos) return false; // Jump out of range
if (pos + jump < pos) return false; // overflow
if (pos + jump > endpos) 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;
Expand Down

0 comments on commit eac6a30

Please sign in to comment.