Coverage Report

Created: 2025-11-11 06:13

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
62.4M
    {
30
62.4M
        return std::hash<std::string>{}(x) & ~15;
31
62.4M
    }
32
};
33
34
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
35
                                      std::size_t size)
36
86.6k
{
37
86.6k
    constexpr auto var_count = 4;
38
39
86.6k
    using set_t =
40
86.6k
        immer::set<std::string, colliding_hash_t, std::equal_to<>, st_memory>;
41
42
86.6k
    auto vars = std::array<set_t, var_count>{};
43
44
549k
    auto is_valid_var = [&](auto idx) { return idx >= 0 && idx < var_count; };
45
46
177k
    return fuzzer_input{data, size}.run([&](auto& in) {
47
177k
        enum ops
48
177k
        {
49
177k
            op_insert,
50
177k
            op_erase,
51
177k
            op_insert_move,
52
177k
            op_erase_move,
53
177k
            op_iterate,
54
177k
            op_diff
55
177k
        };
56
177k
        auto src = read<char>(in, is_valid_var);
57
177k
        auto dst = read<char>(in, is_valid_var);
58
177k
        assert(vars[src].impl().check_champ());
59
174k
        switch (read<char>(in)) {
60
59.3k
        case op_insert: {
61
59.3k
            auto value = std::to_string(read<size_t>(in));
62
59.3k
            vars[dst]  = vars[src].insert(value);
63
59.3k
            break;
64
0
        }
65
8.60k
        case op_erase: {
66
8.60k
            auto value = std::to_string(read<size_t>(in));
67
8.60k
            vars[dst]  = vars[src].erase(value);
68
8.60k
            break;
69
0
        }
70
39.6k
        case op_insert_move: {
71
39.6k
            auto value = std::to_string(read<size_t>(in));
72
39.6k
            vars[dst]  = std::move(vars[src]).insert(value);
73
39.6k
            break;
74
0
        }
75
18.6k
        case op_erase_move: {
76
18.6k
            auto value = std::to_string(read<size_t>(in));
77
18.6k
            vars[dst]  = std::move(vars[src]).erase(value);
78
18.6k
            break;
79
0
        }
80
9.17k
        case op_iterate: {
81
9.17k
            auto srcv = vars[src];
82
484k
            for (const auto& v : srcv) {
83
484k
                vars[dst] = vars[dst].insert(v);
84
484k
            }
85
9.17k
            break;
86
0
        }
87
16.2k
        case op_diff: {
88
16.2k
            auto&& a = vars[src];
89
16.2k
            auto&& b = vars[dst];
90
16.2k
            diff(
91
16.2k
                a,
92
16.2k
                b,
93
66.1k
                [&](auto&& x) {
94
66.1k
                    assert(!a.count(x));
95
66.1k
                    assert(b.count(x));
96
66.1k
                },
97
66.1k
                [&](auto&& x) {
98
66.1k
                    assert(a.count(x));
99
66.1k
                    assert(!b.count(x));
100
66.1k
                },
101
16.2k
                [&](auto&& x, auto&& y) { assert(false); });
102
16.2k
        }
103
38.9k
        default:
104
38.9k
            break;
105
174k
        };
106
174k
        return true;
107
174k
    });
108
86.6k
}