summaryrefslogtreecommitdiff
path: root/lib/fuzzer/FuzzerMutate.cpp
diff options
context:
space:
mode:
authorDan Liew <dan@su-root.co.uk>2018-04-24 06:31:09 +0000
committerDan Liew <dan@su-root.co.uk>2018-04-24 06:31:09 +0000
commita97c9c4c7b68718987d90c9e483be0afa65bea1f (patch)
tree1d2fe2d69a3fa897b760272f645aa822ee60e88b /lib/fuzzer/FuzzerMutate.cpp
parent751fac1ff7dbff433b91becefe86c7b37b825607 (diff)
[LibFuzzer] Tweak `MutationDispatcher::Mutate_CopyPart` mutation.
It doesn't make sense to non-deterministically choose between `CopyPart(..)` and `InsertPart(..)` when it is known that `InsertPart(..)` will fail. This upstream's a change from JFS solver's fork of LibFuzzer. Differential Revision: https://reviews.llvm.org/D45693 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@330687 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/fuzzer/FuzzerMutate.cpp')
-rw-r--r--lib/fuzzer/FuzzerMutate.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/lib/fuzzer/FuzzerMutate.cpp b/lib/fuzzer/FuzzerMutate.cpp
index e0e457852..865e598fd 100644
--- a/lib/fuzzer/FuzzerMutate.cpp
+++ b/lib/fuzzer/FuzzerMutate.cpp
@@ -339,7 +339,9 @@ size_t MutationDispatcher::InsertPartOf(const uint8_t *From, size_t FromSize,
size_t MutationDispatcher::Mutate_CopyPart(uint8_t *Data, size_t Size,
size_t MaxSize) {
if (Size > MaxSize || Size == 0) return 0;
- if (Rand.RandBool())
+ // If Size == MaxSize, `InsertPartOf(...)` will
+ // fail so there's no point using it in this case.
+ if (Size == MaxSize || Rand.RandBool())
return CopyPartOf(Data, Size, Data, Size);
else
return InsertPartOf(Data, Size, Data, Size, MaxSize);