mirror of https://github.com/OpenTTD/OpenTTD
Fix: NewGRF string interpolation did not process all string parameters, if certain string control codes were present.
String control codes with inline data may contain null characters, in particular plural/gender/case choice lists.pull/13851/head
parent
5d291317e7
commit
3b178bf58d
|
@ -764,6 +764,40 @@ static void ProcessNewGRFStringControlCode(char32_t scc, const char *&str, TextR
|
||||||
* After this call, a new call is made with `modify_parameters` set to false when the string is finally formatted. */
|
* After this call, a new call is made with `modify_parameters` set to false when the string is finally formatted. */
|
||||||
switch (scc) {
|
switch (scc) {
|
||||||
default: return;
|
default: return;
|
||||||
|
|
||||||
|
case SCC_PLURAL_LIST:
|
||||||
|
++str; // plural form
|
||||||
|
[[fallthrough]];
|
||||||
|
case SCC_GENDER_LIST: {
|
||||||
|
++str; // offset
|
||||||
|
/* plural and gender choices cannot contain any string commands, so just skip the whole thing */
|
||||||
|
uint num = static_cast<uint8_t>(*str++);
|
||||||
|
uint total_len = 0;
|
||||||
|
for (uint i = 0; i != num; i++) {
|
||||||
|
total_len += static_cast<uint8_t>(*str++);
|
||||||
|
}
|
||||||
|
str += total_len;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SCC_SWITCH_CASE: {
|
||||||
|
/* skip all cases and continue with default case */
|
||||||
|
uint num = static_cast<uint8_t>(*str++);
|
||||||
|
for (uint i = 0; i != num; i++) {
|
||||||
|
str += 3 + (static_cast<uint8_t>(str[1]) << 8) + static_cast<uint8_t>(str[2]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case SCC_GENDER_INDEX:
|
||||||
|
case SCC_SET_CASE:
|
||||||
|
++str;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SCC_ARG_INDEX:
|
||||||
|
NOT_REACHED();
|
||||||
|
break;
|
||||||
|
|
||||||
case SCC_NEWGRF_PRINT_BYTE_SIGNED: params.emplace_back(stack.PopSignedByte()); break;
|
case SCC_NEWGRF_PRINT_BYTE_SIGNED: params.emplace_back(stack.PopSignedByte()); break;
|
||||||
case SCC_NEWGRF_PRINT_QWORD_CURRENCY: params.emplace_back(stack.PopSignedQWord()); break;
|
case SCC_NEWGRF_PRINT_QWORD_CURRENCY: params.emplace_back(stack.PopSignedQWord()); break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue