Make gArbitrary a local

This commit is contained in:
2024-01-24 13:42:29 -08:00
parent bba733fd93
commit 063b51699b

View File

@@ -276,8 +276,6 @@ private:
std::span<const uint8_t> bytecode;
};
Arbitrary gArbitrary;
uint32_t Arbitrary::bounded(uint32_t s) {
if (s == 1) {
return 0;
@@ -1414,27 +1412,27 @@ int main(void) {
#ifdef ENABLE_FUZZ
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
// TODO call setOldestVersion, and check range writes/reads
gArbitrary = Arbitrary{{data, size}};
Arbitrary arbitrary{{data, size}};
int64_t writeVersion = 0;
ConflictSet::Impl cs{writeVersion};
ReferenceImpl refImpl{writeVersion};
while (gArbitrary.hasEntropy()) {
while (arbitrary.hasEntropy()) {
Arena arena;
{
int numWrites = gArbitrary.bounded(10);
int numWrites = arbitrary.bounded(10);
int64_t v = ++writeVersion;
auto *writes = new (arena) ConflictSet::WriteRange[numWrites];
auto keys = set<std::string_view>(arena);
while (int(keys.size()) < numWrites) {
if (!gArbitrary.hasEntropy()) {
if (!arbitrary.hasEntropy()) {
// Tell the fuzzer it's not interesting
return -1;
}
int keyLen = gArbitrary.bounded(8);
int keyLen = arbitrary.bounded(8);
auto *begin = new (arena) uint8_t[keyLen];
gArbitrary.randomBytes(begin, keyLen);
arbitrary.randomBytes(begin, keyLen);
keys.insert(std::string_view((const char *)begin, keyLen));
}
auto iter = keys.begin();
@@ -1458,18 +1456,18 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
abort();
}
{
int numReads = gArbitrary.bounded(10);
int64_t v = writeVersion - gArbitrary.bounded(10);
int numReads = arbitrary.bounded(10);
int64_t v = writeVersion - arbitrary.bounded(10);
auto *reads = new (arena) ConflictSet::ReadRange[numReads];
auto keys = set<std::string_view>(arena);
while (int(keys.size()) < numReads) {
if (!gArbitrary.hasEntropy()) {
if (!arbitrary.hasEntropy()) {
// Tell the fuzzer it's not interesting
return -1;
}
int keyLen = gArbitrary.bounded(8);
int keyLen = arbitrary.bounded(8);
auto *begin = new (arena) uint8_t[keyLen];
gArbitrary.randomBytes(begin, keyLen);
arbitrary.randomBytes(begin, keyLen);
keys.insert(std::string_view((const char *)begin, keyLen));
}
auto iter = keys.begin();