LCOV - code coverage report
Current view: top level - src/test/fuzz - parse_numbers.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 34 34
Test Date: 2025-06-01 05:27:21 Functions: 100.0 % 2 2
Branches: 68.2 % 44 30

             Branch data     Line data    Source code
       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         [ +  - ]:         585 : FUZZ_TARGET(parse_numbers)
      16                 :             : {
      17                 :         143 :     const std::string random_string(buffer.begin(), buffer.end());
      18                 :         143 :     {
      19                 :         143 :         const auto i8{ToIntegral<int8_t>(random_string)};
      20                 :         143 :         const auto u8{ToIntegral<uint8_t>(random_string)};
      21                 :         143 :         const auto i16{ToIntegral<int16_t>(random_string)};
      22                 :         143 :         const auto u16{ToIntegral<uint16_t>(random_string)};
      23                 :         143 :         const auto i32{ToIntegral<int32_t>(random_string)};
      24                 :         143 :         const auto u32{ToIntegral<uint32_t>(random_string)};
      25                 :         143 :         const auto i64{ToIntegral<int64_t>(random_string)};
      26                 :         143 :         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         [ +  + ]:         143 :         if (i8) {
      30         [ +  - ]:           5 :             assert(i8 == i64);
      31                 :             :         }
      32         [ +  + ]:         143 :         if (u8) {
      33         [ +  - ]:           4 :             assert(u8 == u64);
      34                 :             :         }
      35         [ +  + ]:         143 :         if (i16) {
      36         [ +  - ]:           5 :             assert(i16 == i64);
      37                 :             :         }
      38         [ +  + ]:         143 :         if (u16) {
      39         [ +  - ]:           4 :             assert(u16 == u64);
      40                 :             :         }
      41         [ +  + ]:         143 :         if (i32) {
      42         [ +  - ]:           5 :             assert(i32 == i64);
      43                 :             :         }
      44         [ +  + ]:         143 :         if (u32) {
      45         [ +  - ]:           5 :             assert(u32 == u64);
      46                 :             :         }
      47                 :         143 :         constexpr auto digits{"0123456789"};
      48         [ +  + ]:         143 :         if (i64) {
      49   [ +  -  -  + ]:          12 :             assert(util::RemovePrefixView(random_string, "-").find_first_not_of(digits) == std::string::npos);
      50                 :             :         }
      51         [ +  + ]:         143 :         if (u64) {
      52         [ -  + ]:          11 :             assert(random_string.find_first_not_of(digits) == std::string::npos);
      53                 :             :         }
      54                 :             :     }
      55                 :             : 
      56         [ +  - ]:         143 :     (void)ParseMoney(random_string);
      57                 :             : 
      58         [ +  - ]:         143 :     (void)LocaleIndependentAtoi<int>(random_string);
      59                 :             : 
      60                 :         143 :     int64_t i64;
      61         [ +  - ]:         143 :     (void)LocaleIndependentAtoi<int64_t>(random_string);
      62         [ +  - ]:         143 :     (void)ParseFixedPoint(random_string, 3, &i64);
      63                 :         143 : }
        

Generated by: LCOV version 2.0-1