summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-04-27 18:25:53 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-04-27 19:41:51 +0200
commit31c87ba90813a38222002d717d7f03dcf30ebced (patch)
tree0c6dd6f7330b47030b2c1010dcee9465b17901e9 /src
parent0e449f20dcec4e9a04b218205453b40deb947382 (diff)
downloadopenttd-31c87ba90813a38222002d717d7f03dcf30ebced.tar.xz
Fix: truncating strings in settings could leave invalid Utf8 characters
Diffstat (limited to 'src')
-rw-r--r--src/settings.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index 3095c6079..9b97107a3 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -506,7 +506,12 @@ static void Write_ValidateString(void *ptr, const SaveLoad *sld, const char *p)
switch (GetVarMemType(sld->conv)) {
case SLE_VAR_STRB:
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;
case SLE_VAR_STR: