Skip to content

Commit eb7ec32

Browse files
pepyakinkripken
authored andcommitted
Add readData to fuzz support, making it easier to use (#1378)
1 parent 3a13cbe commit eb7ec32

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/tools/fuzzing.h

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ class TranslateToFuzzReader {
5656
public:
5757
TranslateToFuzzReader(Module& wasm, std::string& filename) : wasm(wasm), builder(wasm) {
5858
auto input(read_file<std::vector<char>>(filename, Flags::Binary, Flags::Release));
59-
bytes.swap(input);
60-
pos = 0;
61-
finishedInput = false;
62-
// ensure *some* input to be read
63-
if (bytes.size() == 0) {
64-
bytes.push_back(0);
65-
}
59+
readData(input);
60+
}
61+
62+
TranslateToFuzzReader(Module& wasm, std::vector<char> input) : wasm(wasm), builder(wasm) {
63+
readData(input);
6664
}
6765

6866
void pickPasses(OptimizationOptions& options) {
@@ -180,6 +178,17 @@ class TranslateToFuzzReader {
180178
// so it's not identical
181179
int xorFactor = 0;
182180

181+
182+
void readData(std::vector<char> input) {
183+
bytes.swap(input);
184+
pos = 0;
185+
finishedInput = false;
186+
// ensure *some* input to be read
187+
if (bytes.size() == 0) {
188+
bytes.push_back(0);
189+
}
190+
}
191+
183192
int8_t get() {
184193
if (pos == bytes.size()) {
185194
// we ran out of input, go to the start for more stuff

0 commit comments

Comments
 (0)