diff options
author | Kostya Serebryany <kcc@google.com> | 2019-02-08 22:59:03 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2019-02-08 22:59:03 +0000 |
commit | 114cfafe0585edbdcffbfab2cb32d206f5f02ac7 (patch) | |
tree | 0cb95f3581c9ecacb47d5f224bf39b1ccc3082e1 /compiler-rt/lib/fuzzer/FuzzerMerge.cpp | |
parent | decba8aa06f01ed76a5e2e1d4705b98782132bef (diff) | |
download | bcm5719-llvm-114cfafe0585edbdcffbfab2cb32d206f5f02ac7.tar.gz bcm5719-llvm-114cfafe0585edbdcffbfab2cb32d206f5f02ac7.zip |
[libFuzzer] refactor the merging code, NFC
llvm-svn: 353576
Diffstat (limited to 'compiler-rt/lib/fuzzer/FuzzerMerge.cpp')
-rw-r--r-- | compiler-rt/lib/fuzzer/FuzzerMerge.cpp | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/compiler-rt/lib/fuzzer/FuzzerMerge.cpp b/compiler-rt/lib/fuzzer/FuzzerMerge.cpp index 0d4971af09b..5c590269bfb 100644 --- a/compiler-rt/lib/fuzzer/FuzzerMerge.cpp +++ b/compiler-rt/lib/fuzzer/FuzzerMerge.cpp @@ -230,13 +230,15 @@ void Fuzzer::CrashResistantMergeInternalStep(const std::string &CFPath) { } static void WriteNewControlFile(const std::string &CFPath, - const Vector<SizedFile> &AllFiles, - size_t NumFilesInFirstCorpus) { + const Vector<SizedFile> &OldCorpus, + const Vector<SizedFile> &NewCorpus) { RemoveFile(CFPath); std::ofstream ControlFile(CFPath); - ControlFile << AllFiles.size() << "\n"; - ControlFile << NumFilesInFirstCorpus << "\n"; - for (auto &SF: AllFiles) + ControlFile << (OldCorpus.size() + NewCorpus.size()) << "\n"; + ControlFile << OldCorpus.size() << "\n"; + for (auto &SF: OldCorpus) + ControlFile << SF.File << "\n"; + for (auto &SF: NewCorpus) ControlFile << SF.File << "\n"; if (!ControlFile) { Printf("MERGE-OUTER: failed to write to the control file: %s\n", @@ -245,10 +247,11 @@ static void WriteNewControlFile(const std::string &CFPath, } } -// Outer process. Does not call the target code and thus sohuld not fail. +// Outer process. Does not call the target code and thus should not fail. Vector<std::string> CrashResistantMerge(const Vector<std::string> &Args, - const Vector<std::string> &Corpora, + const Vector<SizedFile> &OldCorpus, + const Vector<SizedFile> &NewCorpus, const std::string &CFPath) { size_t NumAttempts = 0; if (FileSize(CFPath)) { @@ -277,17 +280,10 @@ CrashResistantMerge(const Vector<std::string> &Args, if (!NumAttempts) { // The supplied control file is empty or bad, create a fresh one. - Vector<SizedFile> AllFiles; - GetSizedFilesFromDir(Corpora[0], &AllFiles); - size_t NumFilesInFirstCorpus = AllFiles.size(); - std::sort(AllFiles.begin(), AllFiles.end()); - for (size_t i = 1; i < Corpora.size(); i++) - GetSizedFilesFromDir(Corpora[i], &AllFiles); - std::sort(AllFiles.begin() + NumFilesInFirstCorpus, AllFiles.end()); - Printf("MERGE-OUTER: %zd files, %zd in the initial corpus\n", - AllFiles.size(), NumFilesInFirstCorpus); - WriteNewControlFile(CFPath, AllFiles, NumFilesInFirstCorpus); - NumAttempts = AllFiles.size(); + NumAttempts = OldCorpus.size() + NewCorpus.size(); + Printf("MERGE-OUTER: %zd files, %zd in the initial corpus\n", NumAttempts, + OldCorpus.size()); + WriteNewControlFile(CFPath, OldCorpus, NewCorpus); } // Execute the inner process until it passes. |