Coverage Report

Created: 2026-05-30 06:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/immer/extra/fuzzer/set-st-str.cpp
Line
Count
Source
1
//
2
// immer: immutable data structures for C++
3
// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4
//
5
// This software is distributed under the Boost Software License, Version 1.0.
6
// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7
//
8
9
#include "fuzzer_input.hpp"
10
11
#include <immer/box.hpp>
12
#include <immer/heap/gc_heap.hpp>
13
#include <immer/refcount/no_refcount_policy.hpp>
14
#include <immer/set.hpp>
15
16
#include <immer/algorithm.hpp>
17
18
#include <array>
19
20
using st_memory = immer::memory_policy<immer::heap_policy<immer::cpp_heap>,
21
                                       immer::unsafe_refcount_policy,
22
                                       immer::no_lock_policy,
23
                                       immer::no_transience_policy,
24
                                       false>;
25
26
struct colliding_hash_t
27
{
28
    std::size_t operator()(const std::string& x) const
29
22.0M
    {
30
22.0M
        return std::hash<std::string>{}(x) & ~15;
31
22.0M
    }
32
};
33
34
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
35
                                      std::size_t size)
36
3.25k
{
37
3.25k
    constexpr auto var_count = 4;
38
39
3.25k
    using set_t =
40
3.25k
        immer::set<std::string, colliding_hash_t, std::equal_to<>, st_memory>;
41
42
3.25k
    auto vars = std::array<set_t, var_count>{};
43
44
606k
    auto is_valid_var = [&](auto idx) { return idx >= 0 && idx < var_count; };
45
46
196k
    return fuzzer_input{data, size}.run([&](auto& in) {
47
196k
        enum ops
48
196k
        {
49
196k
            op_insert,
50
196k
            op_erase,
51
196k
            op_insert_move,
52
196k
            op_erase_move,
53
196k
            op_iterate,
54
196k
            op_diff
55
196k
        };
56
196k
        auto src = read<char>(in, is_valid_var);
57
196k
        auto dst = read<char>(in, is_valid_var);
58
196k
        assert(vars[src].impl().check_champ());
59
193k
        switch (read<char>(in)) {
60
64.7k
        case op_insert: {
61
64.7k
            auto value = std::to_string(read<size_t>(in));
62
64.7k
            vars[dst]  = vars[src].insert(value);
63
64.7k
            break;
64
0
        }
65
9.39k
        case op_erase: {
66
9.39k
            auto value = std::to_string(read<size_t>(in));
67
9.39k
            vars[dst]  = vars[src].erase(value);
68
9.39k
            break;
69
0
        }
70
45.5k
        case op_insert_move: {
71
45.5k
            auto value = std::to_string(read<size_t>(in));
72
45.5k
            vars[dst]  = std::move(vars[src]).insert(value);
73
45.5k
            break;
74
0
        }
75
19.8k
        case op_erase_move: {
76
19.8k
            auto value = std::to_string(read<size_t>(in));
77
19.8k
            vars[dst]  = std::move(vars[src]).erase(value);
78
19.8k
            break;
79
0
        }
80
9.03k
        case op_iterate: {
81
9.03k
            auto srcv = vars[src];
82
544k
            for (const auto& v : srcv) {
83
544k
                vars[dst] = vars[dst].insert(v);
84
544k
            }
85
9.03k
            break;
86
0
        }
87
18.2k
        case op_diff: {
88
18.2k
            auto&& a = vars[src];
89
18.2k
            auto&& b = vars[dst];
90
18.2k
            diff(
91
18.2k
                a,
92
18.2k
                b,
93
84.9k
                [&](auto&& x) {
94
84.9k
                    assert(!a.count(x));
95
84.9k
                    assert(b.count(x));
96
84.9k
                },
97
98.8k
                [&](auto&& x) {
98
98.8k
                    assert(a.count(x));
99
98.8k
                    assert(!b.count(x));
100
98.8k
                },
101
18.2k
                [&](auto&& x, auto&& y) { assert(false); });
102
18.2k
        }
103
44.9k
        default:
104
44.9k
            break;
105
193k
        };
106
193k
        return true;
107
193k
    });
108
3.25k
}