Bitcoin Core  24.99.0
P2P Digital Currency
parse_numbers.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2021 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 
9 #include <string>
10 
11 FUZZ_TARGET(parse_numbers)
12 {
13  const std::string random_string(buffer.begin(), buffer.end());
14 
15  (void)ParseMoney(random_string);
16 
17  uint8_t u8;
18  (void)ParseUInt8(random_string, &u8);
19 
20  uint16_t u16;
21  (void)ParseUInt16(random_string, &u16);
22 
23  int32_t i32;
24  (void)ParseInt32(random_string, &i32);
25  (void)LocaleIndependentAtoi<int>(random_string);
26 
27  uint32_t u32;
28  (void)ParseUInt32(random_string, &u32);
29 
30  int64_t i64;
31  (void)LocaleIndependentAtoi<int64_t>(random_string);
32  (void)ParseFixedPoint(random_string, 3, &i64);
33  (void)ParseInt64(random_string, &i64);
34 
35  uint64_t u64;
36  (void)ParseUInt64(random_string, &u64);
37 }
unsigned int u32
unsigned char u8
std::optional< CAmount > ParseMoney(const std::string &money_string)
Parse an amount denoted in full coins.
Definition: moneystr.cpp:42
FUZZ_TARGET(parse_numbers)
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
bool ParseUInt16(std::string_view str, uint16_t *out)
Convert decimal string to unsigned 16-bit integer with strict parse error feedback.
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
bool ParseUInt8(std::string_view str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
bool ParseUInt64(std::string_view str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
bool ParseUInt32(std::string_view str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.