diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/misc_gui.cpp | 2 | ||||
-rw-r--r-- | src/string.cpp | 12 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 2fa779760..3250a3d1b 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1282,7 +1282,7 @@ struct QueryStringWindow : public QueryStringBaseWindow QueryStringBaseWindow(maxsize) { GetString(this->edit_str_buf, str, &this->edit_str_buf[maxsize - 1]); - this->edit_str_buf[maxsize - 1] = '\0'; + str_validate(this->edit_str_buf, &this->edit_str_buf[maxsize - 1], false, true); if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf); 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; + } } } |