Skip to content

Commit

Permalink
Refactor unary minus for unsigned type in MutateString
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Lebedev <lebdron@gmail.com>
  • Loading branch information
lebdron authored and vitalybuka committed Nov 6, 2020
1 parent 8372739 commit 5130879
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/libfuzzer/libfuzzer_mutator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ std::string Mutator::MutateString(const std::string& value,
// any 8 bit types.
if (!std::uniform_int_distribution<uint16_t>(0, 20)(*random())) return {};
std::string result = value;
result.resize(value.size() +
std::max<int>(-value.size(), size_increase_hint));
std::string::size_type new_size = 0;
if (size_increase_hint >= 0 || static_cast<std::string::size_type>(
-size_increase_hint) <= value.size()) {
new_size = value.size() + size_increase_hint;
}
result.resize(new_size);
if (result.empty()) result.push_back(0);
result.resize(LLVMFuzzerMutate(reinterpret_cast<uint8_t*>(&result[0]),
value.size(), result.size()));
Expand Down

0 comments on commit 5130879

Please sign in to comment.