Skip to content

Commit 4830077

Browse files
author
MarcoFalke
committed
Merge #18510: fuzz: Add CScriptNum::getint coverage
faa64af fuzz: Add CScriptNum::getint coverage (MarcoFalke) Pull request description: Add coverage for * https://marcofalke.github.io/btc_cov/fuzz.coverage/src/script/script.h.gcov.html#311 * https://marcofalke.github.io/btc_cov/fuzz.coverage/src/script/script.h.gcov.html#511 ACKs for top commit: practicalswift: ACK faa64af -- more fuzzing coverage is better than less fuzzing coverage :) Tree-SHA512: 1a66a2edc3740e8c286049f6c27458c59c45b01052e51684eec0e1be63ffcee94b4ba3d41d88ad715ceb3e4754fd997cf03899085982454905e86d0553d58199
2 parents 94fd4a5 + faa64af commit 4830077

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/test/fuzz/integer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,21 @@ void test_one_input(const std::vector<uint8_t>& buffer)
126126
assert(parsed_money == i64);
127127
}
128128
}
129+
if (i32 >= 0 && i32 <= 16) {
130+
assert(i32 == CScript::DecodeOP_N(CScript::EncodeOP_N(i32)));
131+
}
132+
129133
const std::chrono::seconds seconds{i64};
130134
assert(count_seconds(seconds) == i64);
131135

136+
const CScriptNum script_num{i64};
137+
(void)script_num.getint();
138+
// Avoid negation failure:
139+
// 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
140+
if (script_num != CScriptNum{std::numeric_limits<int64_t>::min()}) {
141+
(void)script_num.getvch();
142+
}
143+
132144
const arith_uint256 au256 = UintToArith256(u256);
133145
assert(ArithToUint256(au256) == u256);
134146
assert(uint256S(au256.GetHex()) == u256);

src/test/fuzz/scriptnum_ops.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
128128
script_num &= fuzzed_data_provider.ConsumeIntegral<int64_t>();
129129
break;
130130
}
131+
(void)script_num.getint();
131132
// Avoid negation failure:
132133
// 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
133134
if (script_num != CScriptNum{std::numeric_limits<int64_t>::min()}) {

0 commit comments

Comments
 (0)