changeset 16821:f557e79d1ba3 draft

(svn r21555) -Fix [FS#4321]: strings for the query window weren't properly terminated to N characters anymore
author rubidium <rubidium@openttd.org>
date Tue, 21 Dec 2010 09:29:01 +0000
parents acd43b314092
children 2aa42d3a1228
files src/misc_gui.cpp
diffstat 1 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/misc_gui.cpp
+++ b/src/misc_gui.cpp
@@ -1314,6 +1314,12 @@
 		GetString(this->edit_str_buf, str, &this->edit_str_buf[max_bytes - 1]);
 		str_validate(this->edit_str_buf, &this->edit_str_buf[max_bytes - 1], false, true);
 
+		/* Make sure the name isn't too long for the text buffer in the number of
+		 * characters (not bytes). max_chars also counts the '\0' characters. */
+		while (Utf8StringLength(this->edit_str_buf) + 1 > max_chars) {
+			*Utf8PrevChar(this->edit_str_buf + strlen(this->edit_str_buf)) = '\0';
+		}
+
 		if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->orig = strdup(this->edit_str_buf);
 
 		this->caption = caption;