diff --git a/src/script/script.h b/src/script/script.h --- a/src/script/script.h +++ b/src/script/script.h @@ -366,7 +366,8 @@ std::vector result; const bool neg = value < 0; - uint64_t absvalue = neg ? -value : value; + uint64_t absvalue = neg ? ~static_cast(value) + 1 + : static_cast(value); while (absvalue) { result.push_back(absvalue & 0xff); diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -164,13 +164,7 @@ const CScriptNum script_num{i64}; (void)script_num.getint(); - // Avoid negation failure: - // script/script.h:332:35: runtime error: negation of -9223372036854775808 - // cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned - // type to negate this value to itself - if (script_num != CScriptNum{std::numeric_limits::min()}) { - (void)script_num.getvch(); - } + (void)script_num.getvch(); const arith_uint256 au256 = UintToArith256(u256); assert(ArithToUint256(au256) == u256); diff --git a/src/test/fuzz/scriptnum_ops.cpp b/src/test/fuzz/scriptnum_ops.cpp --- a/src/test/fuzz/scriptnum_ops.cpp +++ b/src/test/fuzz/scriptnum_ops.cpp @@ -181,12 +181,6 @@ break; } (void)script_num.getint(); - // Avoid negation failure: - // script/script.h:332:35: runtime error: negation of - // -9223372036854775808 cannot be represented in type 'int64_t' (aka - // 'long'); cast to an unsigned type to negate this value to itself - if (script_num != CScriptNum{std::numeric_limits::min()}) { - (void)script_num.getvch(); - } + (void)script_num.getvch(); } }