Skip to content

Commit

Permalink
refactor: Avoid unsigned integer overflow in script/interpreter.cpp
Browse files Browse the repository at this point in the history
Although unsigned integer overflow is not undefined behavior, it's
preferable to eliminate the need for a UBSan suppression for it.
  • Loading branch information
hebasto committed Mar 8, 2024
1 parent 54172c6 commit 754ba68
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/script/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ bool CastToBool(const valtype& vch)
* Script is a stack machine (like Forth) that evaluates a predicate
* returning a bool indicating valid or not. There are no loops.
*/
#define stacktop(i) (stack.at(stack.size()+(i)))
#define altstacktop(i) (altstack.at(altstack.size()+(i)))
#define stacktop(i) (stack.at(stack.size() - (-(i))))
#define altstacktop(i) (altstack.at(altstack.size() - (-(i))))
static inline void popstack(std::vector<valtype>& stack)
{
if (stack.empty())
Expand Down
1 change: 0 additions & 1 deletion test/sanitizer_suppressions/ubsan
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ unsigned-integer-overflow:MurmurHash3
unsigned-integer-overflow:CBlockPolicyEstimator::processBlockTx
unsigned-integer-overflow:TxConfirmStats::EstimateMedianVal
unsigned-integer-overflow:prevector.h
unsigned-integer-overflow:EvalScript
unsigned-integer-overflow:xoroshiro128plusplus.h
implicit-integer-sign-change:CBlockPolicyEstimator::processBlockTx
implicit-integer-sign-change:SetStdinEcho
Expand Down

0 comments on commit 754ba68

Please sign in to comment.