mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
fuzz: Introduce CallOneOf helper to replace switch-case
Can be reviewed with --ignore-all-space
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user