[llvm] r238658 - [lib/Fuzzer] make assertions more informative and update comments for the user-supplied mutator
Kostya Serebryany
kcc at google.com
Sat May 30 10:33:14 PDT 2015
Author: kcc
Date: Sat May 30 12:33:13 2015
New Revision: 238658
URL: http://llvm.org/viewvc/llvm-project?rev=238658&view=rev
Log:
[lib/Fuzzer] make assertions more informative and update comments for the user-supplied mutator
Modified:
llvm/trunk/lib/Fuzzer/FuzzerInterface.h
llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
Modified: llvm/trunk/lib/Fuzzer/FuzzerInterface.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerInterface.h?rev=238658&r1=238657&r2=238658&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerInterface.h (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerInterface.h Sat May 30 12:33:13 2015
@@ -69,12 +69,12 @@ class UserSuppliedFuzzer {
/// Executes the target function on 'Size' bytes of 'Data'.
virtual void TargetFunction(const uint8_t *Data, size_t Size) = 0;
/// Mutates 'Size' bytes of data in 'Data' inplace into up to 'MaxSize' bytes,
- /// returns the new size of the data.
+ /// returns the new size of the data, which should be positive.
virtual size_t Mutate(uint8_t *Data, size_t Size, size_t MaxSize) {
return BasicMutate(Data, Size, MaxSize);
}
/// Crosses 'Data1' and 'Data2', writes up to 'MaxOutSize' bytes into Out,
- /// returns the number of bytes written.
+ /// returns the number of bytes written, which should be positive.
virtual size_t CrossOver(const uint8_t *Data1, size_t Size1,
const uint8_t *Data2, size_t Size2,
uint8_t *Out, size_t MaxOutSize) {
Modified: llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp?rev=238658&r1=238657&r2=238658&view=diff
==============================================================================
--- llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp (original)
+++ llvm/trunk/lib/Fuzzer/FuzzerLoop.cpp Sat May 30 12:33:13 2015
@@ -289,7 +289,9 @@ void Fuzzer::MutateAndTestOne(Unit *U) {
size_t Size = U->size();
U->resize(Options.MaxLen);
size_t NewSize = USF.Mutate(U->data(), Size, U->size());
- assert(NewSize > 0 && NewSize <= (size_t)Options.MaxLen);
+ assert(NewSize > 0 && "Mutator returned empty unit");
+ assert(NewSize <= (size_t)Options.MaxLen &&
+ "Mutator return overisized unit");
U->resize(NewSize);
RunOneAndUpdateCorpus(*U);
size_t NumTraceBasedMutations = StopTraceRecording();
@@ -317,7 +319,9 @@ void Fuzzer::Loop(size_t NumIterations)
size_t NewSize = USF.CrossOver(
Corpus[J1].data(), Corpus[J1].size(), Corpus[J2].data(),
Corpus[J2].size(), CurrentUnit.data(), CurrentUnit.size());
- assert(NewSize > 0 && NewSize <= (size_t)Options.MaxLen);
+ assert(NewSize > 0 && "CrossOver returned empty unit");
+ assert(NewSize <= (size_t)Options.MaxLen &&
+ "CrossOver return overisized unit");
CurrentUnit.resize(NewSize);
MutateAndTestOne(&CurrentUnit);
}
More information about the llvm-commits
mailing list