forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_numbers.cpp
More file actions
63 lines (57 loc) · 1.93 KB
/
parse_numbers.cpp
File metadata and controls
63 lines (57 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) 2009-2021 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <test/fuzz/fuzz.h>
#include <util/moneystr.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <cassert>
#include <cstdint>
#include <optional>
#include <string>
FUZZ_TARGET(parse_numbers)
{
const std::string random_string(buffer.begin(), buffer.end());
{
const auto i8{ToIntegral<int8_t>(random_string)};
const auto u8{ToIntegral<uint8_t>(random_string)};
const auto i16{ToIntegral<int16_t>(random_string)};
const auto u16{ToIntegral<uint16_t>(random_string)};
const auto i32{ToIntegral<int32_t>(random_string)};
const auto u32{ToIntegral<uint32_t>(random_string)};
const auto i64{ToIntegral<int64_t>(random_string)};
const auto u64{ToIntegral<uint64_t>(random_string)};
// Dont check any values, just that each success result must fit into
// the one with the largest bit-width.
if (i8) {
assert(i8 == i64);
}
if (u8) {
assert(u8 == u64);
}
if (i16) {
assert(i16 == i64);
}
if (u16) {
assert(u16 == u64);
}
if (i32) {
assert(i32 == i64);
}
if (u32) {
assert(u32 == u64);
}
constexpr auto digits{"0123456789"};
if (i64) {
assert(util::RemovePrefixView(random_string, "-").find_first_not_of(digits) == std::string::npos);
}
if (u64) {
assert(random_string.find_first_not_of(digits) == std::string::npos);
}
}
(void)ParseMoney(random_string);
(void)LocaleIndependentAtoi<int>(random_string);
int64_t i64;
(void)LocaleIndependentAtoi<int64_t>(random_string);
(void)ParseFixedPoint(random_string, 3, &i64);
}