diff options
author | Sergey Pepyakin <s.pepyakin@gmail.com> | 2018-01-20 06:11:56 +0300 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2018-01-19 19:11:56 -0800 |
commit | eb7ec3286f781407f9f019b298eb241f4019234b (patch) | |
tree | 3cd1cb9f81b5ec75ca5f3cd79d0c30dacb9d85dd /src | |
parent | 3a13cbeaed21e452b855ce7b132de92d09b9e997 (diff) | |
download | binaryen-eb7ec3286f781407f9f019b298eb241f4019234b.tar.gz binaryen-eb7ec3286f781407f9f019b298eb241f4019234b.tar.bz2 binaryen-eb7ec3286f781407f9f019b298eb241f4019234b.zip |
Add readData to fuzz support, making it easier to use (#1378)
Diffstat (limited to 'src')
-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 |