Bitcoin Core Fuzz Coverage Report

Coverage Report

Created: 2026-03-24 13:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/crypto/hex_base.cpp
Line
Count
Source
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 <crypto/hex_base.h>
6
7
#include <array>
8
#include <cassert>
9
#include <cstring>
10
#include <string>
11
12
namespace {
13
14
using ByteAsHex = std::array<char, 2>;
15
16
constexpr std::array<ByteAsHex, 256> CreateByteToHexMap()
17
0
{
18
0
    constexpr char hexmap[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
19
0
20
0
    std::array<ByteAsHex, 256> byte_to_hex{};
21
0
    for (size_t i = 0; i < byte_to_hex.size(); ++i) {
22
0
        byte_to_hex[i][0] = hexmap[i >> 4];
23
0
        byte_to_hex[i][1] = hexmap[i & 15];
24
0
    }
25
0
    return byte_to_hex;
26
0
}
27
28
} // namespace
29
30
std::string HexStr(const std::span<const uint8_t> s)
31
0
{
32
0
    std::string rv(s.size() * 2, '\0');
33
0
    static constexpr auto byte_to_hex = CreateByteToHexMap();
34
0
    static_assert(sizeof(byte_to_hex) == 512);
35
36
0
    char* it = rv.data();
37
0
    for (uint8_t v : s) {
38
0
        std::memcpy(it, byte_to_hex[v].data(), 2);
39
0
        it += 2;
40
0
    }
41
42
0
    assert(it == rv.data() + rv.size());
43
0
    return rv;
44
0
}
45
46
const signed char p_util_hexdigit[256] =
47
{ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
48
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
49
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
50
  0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
51
  -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
52
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
53
  -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
54
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
55
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
56
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
57
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
58
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
59
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
60
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
61
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
62
  -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
63
64
signed char HexDigit(char c)
65
0
{
66
0
    return p_util_hexdigit[(unsigned char)c];
67
0
}
68