Coverage Report

Created: 2025-06-06 15:08

/root/bitcoin/src/test/fuzz/parse_numbers.cpp
Line
Count
Source (jump to first uncovered line)
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
#include <util/string.h>
9
10
#include <cassert>
11
#include <cstdint>
12
#include <optional>
13
#include <string>
14
15
FUZZ_TARGET(parse_numbers)
16
0
{
17
0
    const std::string random_string(buffer.begin(), buffer.end());
18
0
    {
19
0
        const auto i8{ToIntegral<int8_t>(random_string)};
20
0
        const auto u8{ToIntegral<uint8_t>(random_string)};
21
0
        const auto i16{ToIntegral<int16_t>(random_string)};
22
0
        const auto u16{ToIntegral<uint16_t>(random_string)};
23
0
        const auto i32{ToIntegral<int32_t>(random_string)};
24
0
        const auto u32{ToIntegral<uint32_t>(random_string)};
25
0
        const auto i64{ToIntegral<int64_t>(random_string)};
26
0
        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
0
        if (i8) {
30
0
            assert(i8 == i64);
31
0
        }
32
0
        if (u8) {
33
0
            assert(u8 == u64);
34
0
        }
35
0
        if (i16) {
36
0
            assert(i16 == i64);
37
0
        }
38
0
        if (u16) {
39
0
            assert(u16 == u64);
40
0
        }
41
0
        if (i32) {
42
0
            assert(i32 == i64);
43
0
        }
44
0
        if (u32) {
45
0
            assert(u32 == u64);
46
0
        }
47
0
        constexpr auto digits{"0123456789"};
48
0
        if (i64) {
49
0
            assert(util::RemovePrefixView(random_string, "-").find_first_not_of(digits) == std::string::npos);
50
0
        }
51
0
        if (u64) {
52
0
            assert(random_string.find_first_not_of(digits) == std::string::npos);
53
0
        }
54
0
    }
55
56
0
    (void)ParseMoney(random_string);
57
58
0
    (void)LocaleIndependentAtoi<int>(random_string);
59
60
0
    int64_t i64;
61
0
    (void)LocaleIndependentAtoi<int64_t>(random_string);
62
0
    (void)ParseFixedPoint(random_string, 3, &i64);
63
0
}