mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-24 07:28:02 +01:00
util: Add ConsumeArithUInt256InRange fuzzing helper
This commit is contained in:
parent
f1bcf3edc5
commit
fa327c77e3
1 changed files with 16 additions and 0 deletions
|
@ -180,6 +180,22 @@ template <typename WeakEnumType, size_t size>
|
|||
return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
|
||||
}
|
||||
|
||||
[[nodiscard]] inline arith_uint256 ConsumeArithUInt256InRange(FuzzedDataProvider& fuzzed_data_provider, const arith_uint256& min, const arith_uint256& max) noexcept
|
||||
{
|
||||
assert(min <= max);
|
||||
const arith_uint256 range = max - min;
|
||||
const arith_uint256 value = ConsumeArithUInt256(fuzzed_data_provider);
|
||||
arith_uint256 result = value;
|
||||
// Avoid division by 0, in case range + 1 results in overflow.
|
||||
if (range != ~arith_uint256(0)) {
|
||||
const arith_uint256 quotient = value / (range + 1);
|
||||
result = value - (quotient * (range + 1));
|
||||
}
|
||||
result += min;
|
||||
assert(result >= min && result <= max);
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
||||
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||
|
|
Loading…
Add table
Reference in a new issue