Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions icu4c/source/test/fuzzer/plurrule_fuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


void TestPluralRules(icu::PluralRules* pp, int32_t number, double dbl, UErrorCode& status) {
if (U_FAILURE(status)) {
if (U_FAILURE(status) || pp == nullptr) {
return;
}
pp->select(number);
Expand All @@ -31,8 +31,8 @@ void TestPluralRulesWithLocale(
pp.reset(icu::PluralRules::forLocale(locale, type, status));
TestPluralRules(pp.get(), number, dbl, status);

type = static_cast<UPluralType>(
static_cast<int>(type) % (static_cast<int>(UPLURAL_TYPE_COUNT)));
// Clamp type to valid values: 0 (CARDINAL) or 1 (ORDINAL)
type = static_cast<UPluralType>(static_cast<int>(type) % 2);

status = U_ZERO_ERROR;
pp.reset(icu::PluralRules::forLocale(locale, type, status));
Expand Down Expand Up @@ -63,6 +63,9 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
std::memcpy(&type, fuzzData.data(), sizeof(type));
fuzzData.remove_prefix(sizeof(type));

// Clamp type to valid values: 0 (CARDINAL) or 1 (ORDINAL)
type = static_cast<UPluralType>(static_cast<int>(type) % 2);

size_t len = fuzzData.size() / sizeof(char16_t);
icu::UnicodeString text(false, reinterpret_cast<const char16_t*>(fuzzData.data()), len);

Expand Down