aboutsummaryrefslogtreecommitdiff
path: root/src/util/asmap.cpp
diff options
context:
space:
mode:
authorBen Woosley <ben.woosley@gmail.com>2020-02-27 17:35:31 -0800
committerBen Woosley <ben.woosley@gmail.com>2020-05-09 00:20:00 -0700
commiteac6a3080d38cfd4eb7204ecd327df213958e51a (patch)
tree847fd15defda06d83404870d88c2f60a51f4c8c3 /src/util/asmap.cpp
parentdf37377e30678ac9b8338ea920e50b7296da6bd5 (diff)
downloadbitcoin-eac6a3080d38cfd4eb7204ecd327df213958e51a.tar.xz
refactor: Rework asmap Interpret to avoid ptrdiff_t
Diffstat (limited to 'src/util/asmap.cpp')
-rw-r--r--src/util/asmap.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/util/asmap.cpp b/src/util/asmap.cpp
index b4090482b9..bd77d74218 100644
--- a/src/util/asmap.cpp
+++ b/src/util/asmap.cpp
@@ -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;
}
@@ -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;