diff options
author | Kostya Serebryany <kcc@google.com> | 2015-02-04 19:10:20 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2015-02-04 19:10:20 +0000 |
commit | 5b266a8a23e79c6ebff90699395a2c5e3f0ef91a (patch) | |
tree | 4abbef2db76de874b1c37c5a58b4c08b11ee67b6 /llvm/lib/Fuzzer/FuzzerMutate.cpp | |
parent | 86abe35cebeedd50b2eff579e3a93057165dbd09 (diff) | |
download | llvm-5b266a8a23e79c6ebff90699395a2c5e3f0ef91a.zip llvm-5b266a8a23e79c6ebff90699395a2c5e3f0ef91a.tar.gz llvm-5b266a8a23e79c6ebff90699395a2c5e3f0ef91a.tar.bz2 |
[fuzzer] make multi-process execution more verbose; fix mutation to actually respect mutation depth and to never produce empty units
llvm-svn: 228170
Diffstat (limited to 'llvm/lib/Fuzzer/FuzzerMutate.cpp')
-rw-r--r-- | llvm/lib/Fuzzer/FuzzerMutate.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/llvm/lib/Fuzzer/FuzzerMutate.cpp b/llvm/lib/Fuzzer/FuzzerMutate.cpp index 2db8fac9..60d5623 100644 --- a/llvm/lib/Fuzzer/FuzzerMutate.cpp +++ b/llvm/lib/Fuzzer/FuzzerMutate.cpp @@ -31,18 +31,25 @@ static char RandCh() { return Special[rand() % (sizeof(Special) - 1)]; } +// Mutate U in place. void Mutate(Unit *U, size_t MaxLen) { assert(MaxLen > 0); assert(U->size() <= MaxLen); + if (U->empty()) { + for (size_t i = 0; i < MaxLen; i++) + U->push_back(RandCh()); + return; + } + assert(!U->empty()); switch (rand() % 3) { case 0: - if (U->size()) + if (U->size() > 1) { U->erase(U->begin() + rand() % U->size()); - break; + break; + } + // Fallthrough case 1: - if (U->empty()) { - U->push_back(RandCh()); - } else if (U->size() < MaxLen) { + if (U->size() < MaxLen) { U->insert(U->begin() + rand() % U->size(), RandCh()); } else { // At MaxLen. uint8_t Ch = RandCh(); @@ -51,12 +58,13 @@ void Mutate(Unit *U, size_t MaxLen) { } break; default: - if (!U->empty()) { - size_t idx = rand() % U->size(); - (*U)[idx] = FlipRandomBit((*U)[idx]); + { + size_t Idx = rand() % U->size(); + (*U)[Idx] = FlipRandomBit((*U)[Idx]); } break; } + assert(!U->empty()); } } // namespace fuzzer |