[libFuzzer] honour -only_ascii=1 when reading the initial corpus. Also, remove ugly #ifdef

llvm-svn: 246689
This commit is contained in:
Kostya Serebryany 2015-09-02 19:08:08 +00:00
parent 2355899d99
commit 9c0479fa99
3 changed files with 10 additions and 5 deletions

View File

@ -53,6 +53,7 @@ void ComputeSHA1(const uint8_t *Data, size_t Len, uint8_t *Out);
// Changes U to contain only ASCII (isprint+isspace) characters.
// Returns true iff U has been changed.
bool ToASCII(Unit &U);
bool IsASCII(const Unit &U);
int NumberOfCpuCores();

View File

@ -136,6 +136,8 @@ void Fuzzer::ShuffleAndMinimize() {
U.clear();
size_t Last = std::min(First + Options.MaxLen, C.size());
U.insert(U.begin(), C.begin() + First, C.begin() + Last);
if (Options.OnlyASCII)
ToASCII(U);
size_t NewCoverage = RunOne(U);
if (NewCoverage) {
MaxCov = NewCoverage;
@ -256,11 +258,7 @@ void Fuzzer::WriteToOutputCorpus(const Unit &U) {
WriteToFile(U, Path);
if (Options.Verbosity >= 2)
Printf("Written to %s\n", Path.c_str());
#ifdef DEBUG
if (Options.OnlyASCII)
for (auto X : U)
assert(isprint(X) || isspace(X));
#endif
assert(!Options.OnlyASCII || IsASCII(U));
}
void Fuzzer::WriteUnitToFileWithPrefix(const Unit &U, const char *Prefix) {

View File

@ -86,4 +86,10 @@ bool ToASCII(Unit &U) {
return Changed;
}
bool IsASCII(const Unit &U) {
for (auto X : U)
if (!(isprint(X) || isspace(X))) return false;
return true;
}
} // namespace fuzzer