fuzz coverage

Coverage Report

Created: 2025-06-01 19:34

/Users/eugenesiegel/btc/bitcoin/src/util/vector.h
Line
Count
Source (jump to first uncovered line)
1
// Copyright (c) 2019-2022 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
#ifndef BITCOIN_UTIL_VECTOR_H
6
#define BITCOIN_UTIL_VECTOR_H
7
8
#include <functional>
9
#include <initializer_list>
10
#include <optional>
11
#include <type_traits>
12
#include <utility>
13
#include <vector>
14
15
/** Construct a vector with the specified elements.
16
 *
17
 * This is preferable over the list initializing constructor of std::vector:
18
 * - It automatically infers the element type from its arguments.
19
 * - If any arguments are rvalue references, they will be moved into the vector
20
 *   (list initialization always copies).
21
 */
22
template<typename... Args>
23
inline std::vector<std::common_type_t<Args...>> Vector(Args&&... args)
24
517
{
25
517
    std::vector<std::common_type_t<Args...>> ret;
26
517
    ret.reserve(sizeof...(args));
27
    // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html
28
517
    (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...};
29
517
    return ret;
30
517
}
Unexecuted instantiation: _Z6VectorIJNSt3__16vectorIhNS0_9allocatorIhEEEEEENS1_INS0_11common_typeIJDpT_EE4typeENS2_IS9_EEEEDpOS6_
Unexecuted instantiation: _Z6VectorIJN10miniscript8internal6MaxIntIjEEEENSt3__16vectorINS4_11common_typeIJDpT_EE4typeENS4_9allocatorISA_EEEEDpOS7_
Unexecuted instantiation: _Z6VectorIJN10miniscript8internal7SatInfoEEENSt3__16vectorINS3_11common_typeIJDpT_EE4typeENS3_9allocatorIS9_EEEEDpOS6_
Unexecuted instantiation: _Z6VectorIJ7CPubKeyEENSt3__16vectorINS1_11common_typeIJDpT_EE4typeENS1_9allocatorIS7_EEEEDpOS4_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI7CPubKeyEENS0_14default_deleteIS6_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI7CPubKeyEENS0_14default_deleteIS6_EEEES9_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI7CPubKeyEENS0_14default_deleteIS6_EEEES9_S9_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
Unexecuted instantiation: _Z6VectorIJRKN10miniscript8internal10InputStackEEENSt3__16vectorINS5_11common_typeIJDpT_EE4typeENS5_9allocatorISB_EEEEDpOS8_
Unexecuted instantiation: _Z6VectorIJhEENSt3__16vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorIS6_EEEEDpOS3_
Unexecuted instantiation: miniscript.cpp:_Z6VectorIJN12_GLOBAL__N_119ScriptParserContext3KeyEEENSt3__16vectorINS3_11common_typeIJDpT_EE4typeENS3_9allocatorIS9_EEEEDpOS6_
Unexecuted instantiation: miniscript.cpp:_Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEENS0_14default_deleteIS8_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISH_EEEEDpOSE_
Unexecuted instantiation: miniscript.cpp:_Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEENS0_14default_deleteIS8_EEEESB_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISH_EEEEDpOSE_
Unexecuted instantiation: miniscript.cpp:_Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIN12_GLOBAL__N_119ScriptParserContext3KeyEEENS0_14default_deleteIS8_EEEESB_SB_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISH_EEEEDpOSE_
Unexecuted instantiation: _Z6VectorIJNSt3__17variantIJ14CNoDestination17PubKeyDestination6PKHash10ScriptHash19WitnessV0ScriptHash16WitnessV0KeyHash16WitnessV1Taproot11PayToAnchor14WitnessUnknownEEESB_SB_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISH_EEEEDpOSE_
Unexecuted instantiation: _Z6VectorIJNSt3__17variantIJ14CNoDestination17PubKeyDestination6PKHash10ScriptHash19WitnessV0ScriptHash16WitnessV0KeyHash16WitnessV1Taproot11PayToAnchor14WitnessUnknownEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISH_EEEEDpOSE_
Unexecuted instantiation: descriptor.cpp:_Z6VectorIJNSt3__110unique_ptrIN12_GLOBAL__N_114PubkeyProviderENS0_14default_deleteIS3_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISC_EEEEDpOS9_
Unexecuted instantiation: _Z6VectorIJ7CScriptEENSt3__16vectorINS1_11common_typeIJDpT_EE4typeENS1_9allocatorIS7_EEEEDpOS4_
Unexecuted instantiation: descriptor.cpp:_Z6VectorIJNSt3__110unique_ptrIN12_GLOBAL__N_114DescriptorImplENS0_14default_deleteIS3_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISC_EEEEDpOS9_
Unexecuted instantiation: _Z6VectorIJRK7CScriptEENSt3__16vectorINS3_11common_typeIJDpT_EE4typeENS3_9allocatorIS9_EEEEDpOS6_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIjEENS0_14default_deleteIS5_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISE_EEEEDpOSB_
Unexecuted instantiation: _Z6VectorIJjEENSt3__16vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorIS6_EEEEDpOS3_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIjEENS0_14default_deleteIS5_EEEES8_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISE_EEEEDpOSB_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeIjEENS0_14default_deleteIS5_EEEES8_S8_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISE_EEEEDpOSB_
Unexecuted instantiation: _Z6VectorIJRNSt3__16vectorIhNS0_9allocatorIhEEEEEENS1_INS0_11common_typeIJDpT_EE4typeENS2_ISA_EEEEDpOS7_
Unexecuted instantiation: _Z6VectorIJ11XOnlyPubKeyEENSt3__16vectorINS1_11common_typeIJDpT_EE4typeENS1_9allocatorIS7_EEEEDpOS4_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEENS0_14default_deleteIS6_EEEEEENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEENS0_14default_deleteIS6_EEEES9_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
Unexecuted instantiation: _Z6VectorIJNSt3__110unique_ptrIKN10miniscript4NodeI11XOnlyPubKeyEENS0_14default_deleteIS6_EEEES9_S9_EENS0_6vectorINS0_11common_typeIJDpT_EE4typeENS0_9allocatorISF_EEEEDpOSC_
_Z6VectorIJRK7uint256RS0_EENSt3__16vectorINS4_11common_typeIJDpT_EE4typeENS4_9allocatorISA_EEEEDpOS7_
Line
Count
Source
24
517
{
25
517
    std::vector<std::common_type_t<Args...>> ret;
26
517
    ret.reserve(sizeof...(args));
27
    // The line below uses the trick from https://www.experts-exchange.com/articles/32502/None-recursive-variadic-templates-with-std-initializer-list.html
28
517
    (void)std::initializer_list<int>{(ret.emplace_back(std::forward<Args>(args)), 0)...};
29
517
    return ret;
30
517
}
31
32
/** Concatenate two vectors, moving elements. */
33
template<typename V>
34
inline V Cat(V v1, V&& v2)
35
49.9k
{
36
49.9k
    v1.reserve(v1.size() + v2.size());
37
49.9k
    for (auto& arg : v2) {
38
20
        v1.push_back(std::move(arg));
39
20
    }
40
49.9k
    return v1;
41
49.9k
}
Unexecuted instantiation: _Z3CatINSt3__16vectorINS1_IhNS0_9allocatorIhEEEENS2_IS4_EEEEET_S7_OS7_
_Z3CatINSt3__16vectorI9RPCResultNS0_9allocatorIS2_EEEEET_S6_OS6_
Line
Count
Source
35
4
{
36
4
    v1.reserve(v1.size() + v2.size());
37
20
    for (auto& arg : v2) {
38
20
        v1.push_back(std::move(arg));
39
20
    }
40
4
    return v1;
41
4
}
Unexecuted instantiation: _Z3CatINSt3__16vectorI6RPCArgNS0_9allocatorIS2_EEEEET_S6_OS6_
_Z3CatINSt3__16vectorIPKcNS0_9allocatorIS3_EEEEET_S7_OS7_
Line
Count
Source
35
49.9k
{
36
49.9k
    v1.reserve(v1.size() + v2.size());
37
49.9k
    for (auto& arg : v2) {
38
0
        v1.push_back(std::move(arg));
39
0
    }
40
49.9k
    return v1;
41
49.9k
}
42
43
/** Concatenate two vectors. */
44
template<typename V>
45
inline V Cat(V v1, const V& v2)
46
99.9k
{
47
99.9k
    v1.reserve(v1.size() + v2.size());
48
199k
    for (const auto& arg : v2) {
49
199k
        v1.push_back(arg);
50
199k
    }
51
99.9k
    return v1;
52
99.9k
}
53
54
/** Clear a vector (or std::deque) and release its allocated memory. */
55
template<typename V>
56
inline void ClearShrink(V& v) noexcept
57
808k
{
58
    // There are various ways to clear a vector and release its memory:
59
    //
60
    // 1. V{}.swap(v)
61
    // 2. v = V{}
62
    // 3. v = {}; v.shrink_to_fit();
63
    // 4. v.clear(); v.shrink_to_fit();
64
    //
65
    // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit()
66
    // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding
67
    // request. Therefore, we use method (1).
68
69
808k
    V{}.swap(v);
70
808k
}
Unexecuted instantiation: _Z11ClearShrinkI8bitdequeILi32768EEEvRT_
Unexecuted instantiation: _Z11ClearShrinkINSt3__15dequeI16CompressedHeaderNS0_9allocatorIS2_EEEEEvRT_
_Z11ClearShrinkINSt3__16vectorIhNS0_9allocatorIhEEEEEvRT_
Line
Count
Source
57
808k
{
58
    // There are various ways to clear a vector and release its memory:
59
    //
60
    // 1. V{}.swap(v)
61
    // 2. v = V{}
62
    // 3. v = {}; v.shrink_to_fit();
63
    // 4. v.clear(); v.shrink_to_fit();
64
    //
65
    // (2) does not appear to release memory in glibc debug mode, even if v.shrink_to_fit()
66
    // follows. (3) and (4) rely on std::vector::shrink_to_fit, which is only a non-binding
67
    // request. Therefore, we use method (1).
68
69
808k
    V{}.swap(v);
70
808k
}
71
72
template<typename V, typename L>
73
inline std::optional<V> FindFirst(const std::vector<V>& vec, const L fnc)
74
0
{
75
0
    for (const auto& el : vec) {
76
0
        if (fnc(el)) {
77
0
            return el;
78
0
        }
79
0
    }
80
0
    return std::nullopt;
81
0
}
Unexecuted instantiation: _Z9FindFirstI14AssumeutxoDataZNK12CChainParams19AssumeutxoForHeightEiEUlRKT_E_ENSt3__18optionalIS2_EERKNS6_6vectorIS2_NS6_9allocatorIS2_EEEET0_
Unexecuted instantiation: _Z9FindFirstI14AssumeutxoDataZNK12CChainParams22AssumeutxoForBlockhashERK7uint256EUlRKT_E_ENSt3__18optionalIS5_EERKNS9_6vectorIS5_NS9_9allocatorIS5_EEEET0_
82
83
#endif // BITCOIN_UTIL_VECTOR_H