summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Fuzzer
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2016-02-13 03:46:26 +0000
committerKostya Serebryany <kcc@google.com>2016-02-13 03:46:26 +0000
commit23194963f7979730c21023771acf97e5a9a3c745 (patch)
treede03262a9e62506c46a46e6f3f1c00b4bc56abea /llvm/lib/Fuzzer
parent292cf0379c2656177361b9be7ee1f3bd316dca8d (diff)
downloadbcm5719-llvm-23194963f7979730c21023771acf97e5a9a3c745.tar.gz
bcm5719-llvm-23194963f7979730c21023771acf97e5a9a3c745.zip
[libFuzzer] simplify CTOR of MutationDispatcher
llvm-svn: 260800
Diffstat (limited to 'llvm/lib/Fuzzer')
-rw-r--r--llvm/lib/Fuzzer/FuzzerInternal.h6
-rw-r--r--llvm/lib/Fuzzer/FuzzerMutate.cpp36
2 files changed, 21 insertions, 21 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerInternal.h b/llvm/lib/Fuzzer/FuzzerInternal.h
index 3ac9ea63603..ded25da847d 100644
--- a/llvm/lib/Fuzzer/FuzzerInternal.h
+++ b/llvm/lib/Fuzzer/FuzzerInternal.h
@@ -174,7 +174,7 @@ private:
class MutationDispatcher {
public:
- MutationDispatcher(Random &Rand);
+ MutationDispatcher(Random &Rand) : Rand(Rand) {}
~MutationDispatcher() {}
/// Indicate that we are about to start a new sequence of mutations.
void StartMutationSequence();
@@ -236,7 +236,6 @@ private:
const char *Name;
};
- void Add(Mutator M) { Mutators.push_back(M); }
size_t AddWordFromDictionary(Dictionary &D, uint8_t *Data, size_t Size,
size_t MaxSize);
@@ -249,10 +248,11 @@ private:
// Persistent dictionary modified by the fuzzer, consists of
// entries that led to successfull discoveries in the past mutations.
Dictionary PersistentAutoDictionary;
- std::vector<Mutator> Mutators;
std::vector<Mutator> CurrentMutatorSequence;
std::vector<DictionaryEntry *> CurrentDictionaryEntrySequence;
const std::vector<Unit> *Corpus = nullptr;
+
+ static Mutator Mutators[];
};
class Fuzzer {
diff --git a/llvm/lib/Fuzzer/FuzzerMutate.cpp b/llvm/lib/Fuzzer/FuzzerMutate.cpp
index ff099f17636..b3442219b16 100644
--- a/llvm/lib/Fuzzer/FuzzerMutate.cpp
+++ b/llvm/lib/Fuzzer/FuzzerMutate.cpp
@@ -18,6 +18,22 @@ namespace fuzzer {
const size_t Dictionary::kMaxDictSize;
+MutationDispatcher::Mutator MutationDispatcher::Mutators[] = {
+ {&MutationDispatcher::Mutate_EraseByte, "EraseByte"},
+ {&MutationDispatcher::Mutate_InsertByte, "InsertByte"},
+ {&MutationDispatcher::Mutate_ChangeByte, "ChangeByte"},
+ {&MutationDispatcher::Mutate_ChangeBit, "ChangeBit"},
+ {&MutationDispatcher::Mutate_ShuffleBytes, "ShuffleBytes"},
+ {&MutationDispatcher::Mutate_ChangeASCIIInteger, "ChangeASCIIInt"},
+ {&MutationDispatcher::Mutate_CrossOver, "CrossOver"},
+ {&MutationDispatcher::Mutate_AddWordFromManualDictionary,
+ "AddFromManualDict"},
+ {&MutationDispatcher::Mutate_AddWordFromTemporaryAutoDictionary,
+ "AddFromTempAutoDict"},
+ {&MutationDispatcher::Mutate_AddWordFromPersistentAutoDictionary,
+ "AddFromPersAutoDict"},
+};
+
size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize, unsigned int Seed) {
Random R(Seed);
MutationDispatcher MD(R);
@@ -233,7 +249,8 @@ size_t MutationDispatcher::Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {
// in which case they will return 0.
// Try several times before returning un-mutated data.
for (int Iter = 0; Iter < 10; Iter++) {
- size_t MutatorIdx = Rand(Mutators.size());
+ size_t NumMutators = sizeof(Mutators) / sizeof(Mutators[0]);
+ size_t MutatorIdx = Rand(NumMutators);
auto M = Mutators[MutatorIdx];
size_t NewSize = (this->*(M.Fn))(Data, Size, MaxSize);
if (NewSize) {
@@ -260,21 +277,4 @@ void MutationDispatcher::ClearAutoDictionary() {
TempAutoDictionary.clear();
}
-MutationDispatcher::MutationDispatcher(Random &Rand) : Rand(Rand) {
- Add({&MutationDispatcher::Mutate_EraseByte, "EraseByte"});
- Add({&MutationDispatcher::Mutate_InsertByte, "InsertByte"});
- Add({&MutationDispatcher::Mutate_ChangeByte, "ChangeByte"});
- Add({&MutationDispatcher::Mutate_ChangeBit, "ChangeBit"});
- Add({&MutationDispatcher::Mutate_ShuffleBytes, "ShuffleBytes"});
- Add({&MutationDispatcher::Mutate_ChangeASCIIInteger, "ChangeASCIIInt"});
- Add({&MutationDispatcher::Mutate_CrossOver, "CrossOver"});
- Add({&MutationDispatcher::Mutate_AddWordFromManualDictionary,
- "AddFromManualDict"});
- Add({&MutationDispatcher::Mutate_AddWordFromTemporaryAutoDictionary,
- "AddFromTempAutoDict"});
- Add({&MutationDispatcher::Mutate_AddWordFromPersistentAutoDictionary,
- "AddFromPersAutoDict"});
-}
-
-
} // namespace fuzzer
OpenPOWER on IntegriCloud