[libFuzzer] ensure that entries in PersistentAutoDictionary are not empty

llvm-svn: 292520
This commit is contained in:
Kostya Serebryany 2017-01-19 21:14:47 +00:00
parent 93c6c18a85
commit a44ebf4d06
1 changed files with 3 additions and 0 deletions

View File

@ -272,6 +272,7 @@ size_t MutationDispatcher::Mutate_AddWordFromTORC(
default: default:
assert(0); assert(0);
} }
if (!DE.GetW().size()) return 0;
Size = ApplyDictionaryEntry(Data, Size, MaxSize, DE); Size = ApplyDictionaryEntry(Data, Size, MaxSize, DE);
if (!Size) return 0; if (!Size) return 0;
DictionaryEntry &DERef = DictionaryEntry &DERef =
@ -462,6 +463,7 @@ void MutationDispatcher::RecordSuccessfulMutationSequence() {
for (auto DE : CurrentDictionaryEntrySequence) { for (auto DE : CurrentDictionaryEntrySequence) {
// PersistentAutoDictionary.AddWithSuccessCountOne(DE); // PersistentAutoDictionary.AddWithSuccessCountOne(DE);
DE->IncSuccessCount(); DE->IncSuccessCount();
assert(DE->GetW().size());
// Linear search is fine here as this happens seldom. // Linear search is fine here as this happens seldom.
if (!PersistentAutoDictionary.ContainsWord(DE->GetW())) if (!PersistentAutoDictionary.ContainsWord(DE->GetW()))
PersistentAutoDictionary.push_back({DE->GetW(), 1}); PersistentAutoDictionary.push_back({DE->GetW(), 1});
@ -476,6 +478,7 @@ void MutationDispatcher::PrintRecommendedDictionary() {
if (V.empty()) return; if (V.empty()) return;
Printf("###### Recommended dictionary. ######\n"); Printf("###### Recommended dictionary. ######\n");
for (auto &DE: V) { for (auto &DE: V) {
assert(DE.GetW().size());
Printf("\""); Printf("\"");
PrintASCII(DE.GetW(), "\""); PrintASCII(DE.GetW(), "\"");
Printf(" # Uses: %zd\n", DE.GetUseCount()); Printf(" # Uses: %zd\n", DE.GetUseCount());