fuzz: Introduce CallOneOf helper to replace switch-case

Can be reviewed with --ignore-all-space
This commit is contained in:
MarcoFalke
2021-01-02 13:38:14 +01:00
parent 9c0b76c709
commit fa75d40ef8
19 changed files with 1097 additions and 1217 deletions

View File

@@ -21,43 +21,37 @@ FUZZ_TARGET(autofile)
FuzzedAutoFileProvider fuzzed_auto_file_provider = ConsumeAutoFile(fuzzed_data_provider);
CAutoFile auto_file = fuzzed_auto_file_provider.open();
while (fuzzed_data_provider.ConsumeBool()) {
switch (fuzzed_data_provider.ConsumeIntegralInRange<int>(0, 5)) {
case 0: {
std::array<uint8_t, 4096> arr{};
try {
auto_file.read((char*)arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
break;
}
case 1: {
const std::array<uint8_t, 4096> arr{};
try {
auto_file.write((const char*)arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
break;
}
case 2: {
try {
auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
break;
}
case 3: {
auto_file.fclose();
break;
}
case 4: {
ReadFromStream(fuzzed_data_provider, auto_file);
break;
}
case 5: {
WriteToStream(fuzzed_data_provider, auto_file);
break;
}
}
CallOneOf(
fuzzed_data_provider,
[&] {
std::array<uint8_t, 4096> arr{};
try {
auto_file.read((char*)arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
},
[&] {
const std::array<uint8_t, 4096> arr{};
try {
auto_file.write((const char*)arr.data(), fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
},
[&] {
try {
auto_file.ignore(fuzzed_data_provider.ConsumeIntegralInRange<size_t>(0, 4096));
} catch (const std::ios_base::failure&) {
}
},
[&] {
auto_file.fclose();
},
[&] {
ReadFromStream(fuzzed_data_provider, auto_file);
},
[&] {
WriteToStream(fuzzed_data_provider, auto_file);
});
}
(void)auto_file.Get();
(void)auto_file.GetType();