summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Pepyakin <s.pepyakin@gmail.com>2018-01-20 06:11:56 +0300
committerAlon Zakai <alonzakai@gmail.com>2018-01-19 19:11:56 -0800
commiteb7ec3286f781407f9f019b298eb241f4019234b (patch)
tree3cd1cb9f81b5ec75ca5f3cd79d0c30dacb9d85dd /src
parent3a13cbeaed21e452b855ce7b132de92d09b9e997 (diff)
downloadbinaryen-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.h23
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