1
0
mirror of https://github.com/OpenTTD/OpenTTD synced 2026-01-17 09:22:42 +01:00

Fix 3d8d0e0d26: Don't assume plural parameter is valid. (#12954)

A crash can occur if the parameter used for a plural isn't a numeric value.
This commit is contained in:
Peter Nelson
2024-09-21 15:04:35 +01:00
committed by GitHub
parent 2eac527439
commit 16b4e737a3

View File

@@ -1098,8 +1098,12 @@ static void FormatString(StringBuilder &builder, const char *str_arg, StringPara
case SCC_PLURAL_LIST: { // {P}
int plural_form = *str++; // contains the plural form for this string
size_t offset = orig_offset + (uint8_t)*str++;
int64_t v = std::get<uint64_t>(args.GetParam(offset)); // contains the number that determines plural
str = ParseStringChoice(str, DeterminePluralForm(v, plural_form), builder);
const uint64_t *v = std::get_if<uint64_t>(&args.GetParam(offset)); // contains the number that determines plural
if (v != nullptr) {
str = ParseStringChoice(str, DeterminePluralForm(static_cast<int64_t>(*v), plural_form), builder);
} else {
builder += "(invalid PLURAL parameter)";
}
break;
}