1
0
Fork 0

Fix #14234, 5aa4ad5135: Crash due to unexpected NUL char in string. (#14235)

Gracefully handle an unexpected NUL character in non-debug builds.
pull/14270/head
Peter Nelson 2025-05-21 18:47:04 +01:00 committed by GitHub
parent 82876c25e0
commit 1d8db2223f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 0 deletions

View File

@ -1113,6 +1113,11 @@ static void FormatString(StringBuilder &builder, std::string_view str_arg, Strin
const uint case_index = str_stack.top().case_index;
char32_t b = consumer.ReadUtf8();
assert(b != 0);
if (b == 0) {
/* A NUL character should never be encountered, but for non-debug builds handle it gracefully. */
builder += "(unexpected NUL)";
continue;
}
if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) {
/* We need to pass some stuff as it might be modified. */