Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
addition_overflow.cpp
Go to the documentation of this file.
1// Copyright (c) 2020-present The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
6#include <test/fuzz/fuzz.h>
7#include <test/fuzz/util.h>
8#include <util/overflow.h>
9
10#include <cstdint>
11#include <string>
12#include <vector>
13
14namespace {
15template <typename T>
17{
21 const auto maybe_add{CheckedAdd(i, j)};
22 const auto sat_add{SaturatingAdd(i, j)};
27#ifndef _MSC_VER
32 assert(i + j == result_builtin);
33 }
34#endif
36 assert(sat_add == std::numeric_limits<T>::min() || sat_add == std::numeric_limits<T>::max());
37 } else {
38 const auto add{i + j};
39 assert(add == maybe_add.value());
40 assert(add == sat_add);
41 }
42}
43} // namespace
44
#define FUZZ_TARGET(...)
Definition fuzz.h:35
#define T(expected, seed, data)
std::optional< T > CheckedAdd(const T i, const T j) noexcept
Definition overflow.h:26
bool AdditionOverflow(const T i, const T j) noexcept
Definition overflow.h:15
T SaturatingAdd(const T i, const T j) noexcept
Definition overflow.h:43
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition time.h:73
assert(!tx.IsCoinBase())
FuzzedDataProvider & fuzzed_data_provider
Definition fees.cpp:38