Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
fuzz_dynarray.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 https://github.com/lrleon/Aleph-w
6
7 This file is part of Aleph-w library
8
9 Copyright (c) 2002-2026 Leandro Rabindranath Leon
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28*/
29
35#include <algorithm>
36#include <cstddef>
37#include <cstdint>
38#include <cstdlib>
39#include <vector>
40
41#include <tpl_dynArray.H>
42
50extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
51{
53 std::vector<int> reference;
54
55 for (size_t i = 0; i < std::min(size, size_t{256}); ++i)
56 {
57 const uint8_t byte = data[i];
58 const int value = static_cast<int>(byte) - 128;
59
60 switch (byte % 5)
61 {
62 case 0:
63 if (reference.size() < 64)
64 {
65 array.append(value);
66 reference.push_back(value);
67 }
68 break;
69 case 1:
70 if (not reference.empty())
71 {
72 if (array.pop() != reference.back())
73 std::abort();
74 reference.pop_back();
75 }
76 break;
77 case 2:
78 array.reverse();
79 std::reverse(reference.begin(), reference.end());
80 break;
81 case 3:
82 if (not reference.empty())
83 {
84 const size_t index = byte % reference.size();
85 array(index) = value;
86 reference[index] = value;
87 }
88 break;
89 case 4:
90 if (not reference.empty())
91 {
92 const size_t new_size = byte % (reference.size() + 1);
93 array.cut(new_size);
94 reference.resize(new_size);
95 }
96 break;
97 }
98
99 if (array.size() != reference.size())
100 std::abort();
101 for (size_t j = 0; j < reference.size(); ++j)
102 if (array(j) != reference[j])
103 std::abort();
104 }
105
106 return 0;
107}
size_t size_t int32_t value
Definition ca-c-api.h:116
void cut(const size_t new_dim=0)
Cut the array to a new dimension; that is, it reduces the dimension of array and frees the remaining ...
DynArray & reverse()
Reverse the order of items in an array.
size_t size() const noexcept
Return the current dimension of array.
T pop()
Remove the last item of array (as if this was a stack)
T & append()
Allocate a new entry to the end of array.
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
Exercise bounded sequences of DynArray mutations.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Lazy and scalable dynamic array implementation.