mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-06-02 23:42:33 +02:00
util: Add ConsumeArithUInt256InRange fuzzing helper
This commit is contained in:
parent
f1bcf3edc5
commit
fa327c77e3
@ -180,6 +180,22 @@ template <typename WeakEnumType, size_t size>
|
|||||||
return UintToArith256(ConsumeUInt256(fuzzed_data_provider));
|
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]] std::map<COutPoint, Coin> ConsumeCoins(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||||
|
|
||||||
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
[[nodiscard]] CTxDestination ConsumeTxDestination(FuzzedDataProvider& fuzzed_data_provider) noexcept;
|
||||||
|
Loading…
Reference in New Issue
Block a user