1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-17 11:39:11 +00:00

Fix: truncating strings in settings could leave invalid Utf8 characters

This commit is contained in:
rubidium42
2021-04-27 18:25:53 +02:00
committed by rubidium42
parent 0e449f20dc
commit 31c87ba908

View File

@@ -506,7 +506,12 @@ static void Write_ValidateString(void *ptr, const SaveLoad *sld, const char *p)
switch (GetVarMemType(sld->conv)) { switch (GetVarMemType(sld->conv)) {
case SLE_VAR_STRB: case SLE_VAR_STRB:
case SLE_VAR_STRBQ: case SLE_VAR_STRBQ:
if (p != nullptr) strecpy((char*)ptr, (const char*)p, (char*)ptr + sld->length - 1); if (p != nullptr) {
char *begin = (char*)ptr;
char *end = begin + sld->length - 1;
strecpy(begin, p, end);
str_validate(begin, end, SVS_NONE);
}
break; break;
case SLE_VAR_STR: case SLE_VAR_STR: