Files
conflict-range/cpp/tests/fuzz_raw.cpp
T

44 lines
1.6 KiB
C++

// Released under Apache 2.0 license as described in the file LICENSE.
// libFuzzer safety harness: arbitrary (not necessarily readable) instances.
// Equivalence is only promised on readable inputs, so this harness merely runs
// both implementations under ASan/UBSan to catch memory-safety or UB issues in
// the defensive branches.
#include <cstddef>
#include <cstdint>
#include <vector>
#include "../src/fast.h"
#include "../src/literal.h"
#include "readable_gen.h"
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
std::size_t size) {
cr::gen::Bytes bytes{data, size, 0};
for (int i = 0; i < 8; ++i) {
const std::size_t maxLen = 1 + bytes.u8() % 16;
// Owned selector keys and reported keys; the borrows below point here.
cr::OptKey beginKey = cr::gen::randomOptKey(bytes, maxLen);
cr::OptKey endKey = cr::gen::randomOptKey(bytes, maxLen);
cr::RangeRead r;
r.begin = cr::Selector{cr::optView(beginKey),
cr::gen::randomOffset(bytes)};
r.end_ = cr::Selector{cr::optView(endKey), cr::gen::randomOffset(bytes)};
r.reverse = (bytes.u8() & 1) != 0;
std::vector<cr::Key> keys;
const std::size_t n = bytes.u8() % 16;
keys.reserve(n);
for (std::size_t j = 0; j < n; ++j)
keys.push_back(cr::gen::randomKey(bytes, maxLen));
std::vector<cr::KeyView> views;
views.reserve(keys.size());
for (const cr::Key& k : keys) views.push_back(k);
cr::Result res{views, (bytes.u8() & 1) != 0};
(void)cr::literal::closedForm(r, res);
(void)cr::fast::closedForm(r, res);
}
return 0;
}