Changeset View
Changeset View
Standalone View
Standalone View
src/test/fuzz/util.h
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#ifndef BITCOIN_TEST_FUZZ_UTIL_H | #ifndef BITCOIN_TEST_FUZZ_UTIL_H | ||||
#define BITCOIN_TEST_FUZZ_UTIL_H | #define BITCOIN_TEST_FUZZ_UTIL_H | ||||
#include <amount.h> | #include <amount.h> | ||||
#include <arith_uint256.h> | |||||
#include <attributes.h> | #include <attributes.h> | ||||
#include <script/script.h> | #include <script/script.h> | ||||
#include <serialize.h> | #include <serialize.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <uint256.h> | #include <uint256.h> | ||||
#include <version.h> | #include <version.h> | ||||
#include <test/fuzz/FuzzedDataProvider.h> | #include <test/fuzz/FuzzedDataProvider.h> | ||||
▲ Show 20 Lines • Show All 86 Lines • ▼ Show 20 Lines | ConsumeUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept { | ||||
const std::vector<uint8_t> v256 = | const std::vector<uint8_t> v256 = | ||||
fuzzed_data_provider.ConsumeBytes<uint8_t>(sizeof(uint256)); | fuzzed_data_provider.ConsumeBytes<uint8_t>(sizeof(uint256)); | ||||
if (v256.size() != sizeof(uint256)) { | if (v256.size() != sizeof(uint256)) { | ||||
return {}; | return {}; | ||||
} | } | ||||
return uint256{v256}; | return uint256{v256}; | ||||
} | } | ||||
NODISCARD inline arith_uint256 | |||||
ConsumeArithUInt256(FuzzedDataProvider &fuzzed_data_provider) noexcept { | |||||
return UintToArith256(ConsumeUInt256(fuzzed_data_provider)); | |||||
} | |||||
template <typename T> | template <typename T> | ||||
NODISCARD bool MultiplicationOverflow(const T i, const T j) noexcept { | NODISCARD bool MultiplicationOverflow(const T i, const T j) noexcept { | ||||
static_assert(std::is_integral<T>::value, "Integral required."); | static_assert(std::is_integral<T>::value, "Integral required."); | ||||
if (std::numeric_limits<T>::is_signed) { | if (std::numeric_limits<T>::is_signed) { | ||||
if (i > 0) { | if (i > 0) { | ||||
if (j > 0) { | if (j > 0) { | ||||
return i > (std::numeric_limits<T>::max() / j); | return i > (std::numeric_limits<T>::max() / j); | ||||
} else { | } else { | ||||
Show All 15 Lines |