diff options
author | Kostya Serebryany <kcc@google.com> | 2016-02-13 03:46:26 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2016-02-13 03:46:26 +0000 |
commit | 23194963f7979730c21023771acf97e5a9a3c745 (patch) | |
tree | de03262a9e62506c46a46e6f3f1c00b4bc56abea /llvm/lib/Fuzzer/FuzzerMutate.cpp | |
parent | 292cf0379c2656177361b9be7ee1f3bd316dca8d (diff) | |
download | bcm5719-llvm-23194963f7979730c21023771acf97e5a9a3c745.tar.gz bcm5719-llvm-23194963f7979730c21023771acf97e5a9a3c745.zip |
[libFuzzer] simplify CTOR of MutationDispatcher
llvm-svn: 260800
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerMutate.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerMutate.cpp | 36 |
1 files changed, 18 insertions, 18 deletions
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 |