From faa64af960b64b522bb088e836c9d8cd6254c6c8 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Fri, 3 Apr 2020 09:07:00 +0800 Subject: [PATCH] fuzz: Add CScriptNum::getint coverage --- src/test/fuzz/integer.cpp | 12 ++++++++++++ src/test/fuzz/scriptnum_ops.cpp | 1 + 2 files changed, 13 insertions(+) diff --git a/src/test/fuzz/integer.cpp b/src/test/fuzz/integer.cpp index bd2e20030da..fff2fabd178 100644 --- a/src/test/fuzz/integer.cpp +++ b/src/test/fuzz/integer.cpp @@ -126,9 +126,21 @@ void test_one_input(const std::vector& buffer) assert(parsed_money == i64); } } + if (i32 >= 0 && i32 <= 16) { + assert(i32 == CScript::DecodeOP_N(CScript::EncodeOP_N(i32))); + } + const std::chrono::seconds seconds{i64}; assert(count_seconds(seconds) == i64); + 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(); + } + const arith_uint256 au256 = UintToArith256(u256); assert(ArithToUint256(au256) == u256); assert(uint256S(au256.GetHex()) == u256); diff --git a/src/test/fuzz/scriptnum_ops.cpp b/src/test/fuzz/scriptnum_ops.cpp index db44bb9e19a..42b1432f13a 100644 --- a/src/test/fuzz/scriptnum_ops.cpp +++ b/src/test/fuzz/scriptnum_ops.cpp @@ -128,6 +128,7 @@ void test_one_input(const std::vector& buffer) script_num &= fuzzed_data_provider.ConsumeIntegral(); 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()}) {