diff options
author | Darkvater <darkvater@openttd.org> | 2006-04-06 19:11:41 +0000 |
---|---|---|
committer | Darkvater <darkvater@openttd.org> | 2006-04-06 19:11:41 +0000 |
commit | b68b9b149a5a0c969de94f192420d953c14b1109 (patch) | |
tree | 0c757bee941699bbd6bd6b5291cf2d22688471e2 /misc_gui.c | |
parent | 558ecb16317bccb53e534f561c659844bcd89df5 (diff) | |
download | openttd-b68b9b149a5a0c969de94f192420d953c14b1109.tar.xz |
(svn r4301) - Fix: the maxlength parameter of Textbuf is supposed to be the size of the buffer (so length of string + '\0'), but in the code it was a mix of both. It didn't cause any problems though, only an occasionaly one-less character than allowed. (thanks Tron for noticing)
Diffstat (limited to 'misc_gui.c')
-rw-r--r-- | misc_gui.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/misc_gui.c b/misc_gui.c index f504cb457..3026a0d71 100644 --- a/misc_gui.c +++ b/misc_gui.c @@ -808,8 +808,9 @@ void DeleteTextBufferAll(Textbuf *tb) } /** - * Insert a character to a textbuffer. If maxlength is zero, we don't care about - * the screenlength but only about the physical length of the string + * Insert a character to a textbuffer. If maxlength of the Textbuf is zero, + * we don't care about the screenlength but only about the physical + * length of the string * @param tb @Textbuf type to be changed * @param key Character to be inserted * @return Return true on successfull change of Textbuf, or false otherwise @@ -817,7 +818,7 @@ void DeleteTextBufferAll(Textbuf *tb) bool InsertTextBufferChar(Textbuf *tb, byte key) { const byte charwidth = GetCharacterWidth(key); - if (tb->length < tb->maxlength && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) { + if (tb->length < (tb->maxlength - 1) && (tb->maxwidth == 0 || tb->width + charwidth <= tb->maxwidth)) { memmove(tb->buf + tb->caretpos + 1, tb->buf + tb->caretpos, (tb->length - tb->caretpos) + 1); tb->buf[tb->caretpos] = key; tb->length++; @@ -875,12 +876,12 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode) */ void UpdateTextBufferSize(Textbuf *tb) { - const char* buf; + const char *buf; tb->length = 0; tb->width = 0; - for (buf = tb->buf; *buf != '\0' && tb->length <= tb->maxlength; buf++) { + for (buf = tb->buf; *buf != '\0' && tb->length < (tb->maxlength - 1); buf++) { tb->length++; tb->width += GetCharacterWidth((byte)*buf); } @@ -1078,7 +1079,7 @@ void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, WP(w, querystr_d).wnd_class = window_class; WP(w, querystr_d).wnd_num = window_number; WP(w, querystr_d).text.caret = false; - WP(w, querystr_d).text.maxlength = realmaxlen - 1; + WP(w, querystr_d).text.maxlength = realmaxlen; WP(w, querystr_d).text.maxwidth = maxwidth; WP(w, querystr_d).text.buf = _edit_str_buf; UpdateTextBufferSize(&WP(w, querystr_d).text); @@ -1464,7 +1465,7 @@ void ShowSaveLoadDialog(int mode) w->resize.height = w->height - 14 * 10; // Minimum of 10 items SETBIT(w->click_state, 7); WP(w,querystr_d).text.caret = false; - WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf) - 1; + WP(w,querystr_d).text.maxlength = lengthof(_edit_str_buf); WP(w,querystr_d).text.maxwidth = 240; WP(w,querystr_d).text.buf = _edit_str_buf; UpdateTextBufferSize(&WP(w, querystr_d).text); |