diff options
-rw-r--r-- | src/tools/fuzzing.h | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/tools/fuzzing.h b/src/tools/fuzzing.h index 4bbd4df69..0b3dbf78e 100644 --- a/src/tools/fuzzing.h +++ b/src/tools/fuzzing.h @@ -56,13 +56,11 @@ class TranslateToFuzzReader { public: TranslateToFuzzReader(Module& wasm, std::string& filename) : wasm(wasm), builder(wasm) { auto input(read_file<std::vector<char>>(filename, Flags::Binary, Flags::Release)); - bytes.swap(input); - pos = 0; - finishedInput = false; - // ensure *some* input to be read - if (bytes.size() == 0) { - bytes.push_back(0); - } + readData(input); + } + + TranslateToFuzzReader(Module& wasm, std::vector<char> input) : wasm(wasm), builder(wasm) { + readData(input); } void pickPasses(OptimizationOptions& options) { @@ -180,6 +178,17 @@ private: // so it's not identical int xorFactor = 0; + + void readData(std::vector<char> input) { + bytes.swap(input); + pos = 0; + finishedInput = false; + // ensure *some* input to be read + if (bytes.size() == 0) { + bytes.push_back(0); + } + } + int8_t get() { if (pos == bytes.size()) { // we ran out of input, go to the start for more stuff |