summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2010-07-25 23:14:59 +0000
committerrubidium <rubidium@openttd.org>2010-07-25 23:14:59 +0000
commit80cc566553ca1eb33566e0b05a49b7112d98718d (patch)
treedefede1eb59600b47a413257d23c1642504c1da2 /src/string.cpp
parentb38c4f897a05208b9c740cf5446069d6bf2cbd9c (diff)
downloadopenttd-80cc566553ca1eb33566e0b05a49b7112d98718d.tar.xz
(svn r20220) -Fix [FS#3974]: strip non-printable characters before showing it in an edit box, so when renaming a vehicle type you won't get the "SETX stuff" that some NewGRFs use
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 79bf72c2d..414abf944 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -113,7 +113,7 @@ void str_validate(char *str, const char *last, bool allow_newlines, bool ignore)
/* Assume the ABSOLUTE WORST to be in str as it comes from the outside. */
char *dst = str;
- while (*str != '\0') {
+ while (str <= last && *str != '\0') {
size_t len = Utf8EncodedCharLen(*str);
/* If the character is unknown, i.e. encoded length is 0
* we assume worst case for the length check.
@@ -146,6 +146,16 @@ void str_validate(char *str, const char *last, bool allow_newlines, bool ignore)
/* Replace the undesirable character with a question mark */
str += len;
if (!ignore) *dst++ = '?';
+
+ /* In case of these two special cases assume that they really
+ * mean SETX/SETXY and also "eat" the paramater. If this was
+ * not the case the string was broken to begin with and this
+ * would not break much more. */
+ if (c == SCC_SETX) {
+ str++;
+ } else if (c == SCC_SETXY) {
+ str += 2;
+ }
}
}