summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2007-03-10 00:26:19 +0000
committerDarkvater <Darkvater@openttd.org>2007-03-10 00:26:19 +0000
commita59eec1c3653a52e27fb566569c566b549dd4ef6 (patch)
tree99664ed696ad27f17a26b0a7c3b445f7064f89f4
parent6fe5620876c8d064a7d688869edb9fd50053f3bb (diff)
downloadopenttd-a59eec1c3653a52e27fb566569c566b549dd4ef6.tar.xz
(svn r9083) -Codechange: Be more lenient when trimming UTF-8 strings and don't terminate the string when an invalid encoding is encountered, but only focus on maximum length.
-rw-r--r--src/string.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index b5957622e..aea4bad9d 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -282,7 +282,8 @@ size_t Utf8TrimString(char *s, size_t maxlen)
for (const char *ptr = strchr(s, '\0'); *s != '\0';) {
size_t len = Utf8EncodedCharLen(*s);
- if (len == 0) break; // invalid encoding
+ /* Silently ignore invalid UTF8 sequences, our only concern trimming */
+ if (len == 0) len = 1;
/* Take care when a hard cutoff was made for the string and
* the last UTF8 sequence is invalid */