Skip to content

Commit e5869dd

Browse files
committed
Simplify string resizing
1 parent 5130879 commit e5869dd

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/libfuzzer/libfuzzer_mutator.cc

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,8 @@ std::string Mutator::MutateString(const std::string& value,
8989
// any 8 bit types.
9090
if (!std::uniform_int_distribution<uint16_t>(0, 20)(*random())) return {};
9191
std::string result = value;
92-
std::string::size_type new_size = 0;
93-
if (size_increase_hint >= 0 || static_cast<std::string::size_type>(
94-
-size_increase_hint) <= value.size()) {
95-
new_size = value.size() + size_increase_hint;
96-
}
97-
result.resize(new_size);
98-
if (result.empty()) result.push_back(0);
92+
int new_size = value.size() + size_increase_hint;
93+
result.resize(std::max(1, new_size));
9994
result.resize(LLVMFuzzerMutate(reinterpret_cast<uint8_t*>(&result[0]),
10095
value.size(), result.size()));
10196
return result;

0 commit comments

Comments
 (0)