Bitcoin Core
31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
src
test
fuzz
parse_numbers.cpp
Go to the documentation of this file.
1
// Copyright (c) 2009-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
5
#include <
test/fuzz/fuzz.h
>
6
#include <
util/moneystr.h
>
7
#include <
util/strencodings.h
>
8
#include <
util/string.h
>
9
10
#include <cassert>
11
#include <cstdint>
12
#include <optional>
13
#include <string>
14
15
FUZZ_TARGET
(
parse_numbers
)
16
{
17
const
std::string
random_string
(buffer.begin(), buffer.end());
18
{
19
const
auto
i8
{
ToIntegral<int8_t>
(
random_string
)};
20
const
auto
u8
{
ToIntegral<uint8_t>
(
random_string
)};
21
const
auto
i16
{
ToIntegral<int16_t>
(
random_string
)};
22
const
auto
u16
{
ToIntegral<uint16_t>
(
random_string
)};
23
const
auto
i32
{
ToIntegral<int32_t>
(
random_string
)};
24
const
auto
u32
{
ToIntegral<uint32_t>
(
random_string
)};
25
const
auto
i64
{
ToIntegral<int64_t>
(
random_string
)};
26
const
auto
u64
{
ToIntegral<uint64_t>
(
random_string
)};
27
// Dont check any values, just that each success result must fit into
28
// the one with the largest bit-width.
29
if
(
i8
) {
30
assert
(
i8
==
i64
);
31
}
32
if
(
u8
) {
33
assert
(
u8
==
u64
);
34
}
35
if
(
i16
) {
36
assert
(
i16
==
i64
);
37
}
38
if
(
u16
) {
39
assert
(
u16
==
u64
);
40
}
41
if
(
i32
) {
42
assert
(
i32
==
i64
);
43
}
44
if
(
u32
) {
45
assert
(
u32
==
u64
);
46
}
47
constexpr
auto
digits
{
"0123456789"
};
48
if
(
i64
) {
49
assert
(
util::RemovePrefixView
(
random_string
,
"-"
).
find_first_not_of
(
digits
) == std::string::npos);
50
}
51
if
(
u64
) {
52
assert
(
random_string
.find_first_not_of(
digits
) == std::string::npos);
53
}
54
}
55
56
(
void
)
ParseMoney
(
random_string
);
57
58
(
void
)
LocaleIndependentAtoi<int>
(
random_string
);
59
60
int64_t
i64
;
61
(
void
)
LocaleIndependentAtoi<int64_t>
(
random_string
);
62
(
void
)
ParseFixedPoint
(
random_string
, 3, &
i64
);
63
}
u32
unsigned int u32
Definition
crypto_diff_fuzz_chacha20.cpp:20
u8
unsigned char u8
Definition
crypto_diff_fuzz_chacha20.cpp:21
fuzz.h
FUZZ_TARGET
#define FUZZ_TARGET(...)
Definition
fuzz.h:35
ParseMoney
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition
moneystr.cpp:45
moneystr.h
util::RemovePrefixView
std::string_view RemovePrefixView(std::string_view str, std::string_view prefix)
Definition
string.h:182
strencodings.h
string.h
random_string
std::string random_string(uint32_t length)
Definition
test_kernel.cpp:29
ParseFixedPoint
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
Definition
strencodings.cpp:271
Ticks
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.
Definition
time.h:73
assert
assert(!tx.IsCoinBase())
Generated on Thu Apr 16 2026 09:42:38 for Bitcoin Core by
1.10.0