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 /win32.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 'win32.c')
-rw-r--r-- | win32.c | 7 |
1 files changed, 3 insertions, 4 deletions
@@ -1228,14 +1228,13 @@ bool InsertTextBufferClipboard(Textbuf *tb) data = GlobalLock(cbuf); // clipboard data dataptr = data; - for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < tb->maxlength - 1 && + for (; IsValidAsciiChar(*dataptr) && (tb->length + length) < (tb->maxlength - 1) && (tb->maxwidth == 0 || width + tb->width + GetCharacterWidth((byte)*dataptr) <= tb->maxwidth); dataptr++) { width += GetCharacterWidth((byte)*dataptr); length++; } - if (length == 0) - return false; + if (length == 0) return false; memmove(tb->buf + tb->caretpos + length, tb->buf + tb->caretpos, tb->length - tb->caretpos); memcpy(tb->buf + tb->caretpos, data, length); @@ -1244,7 +1243,7 @@ bool InsertTextBufferClipboard(Textbuf *tb) tb->length += length; tb->caretpos += length; - tb->buf[tb->length + 1] = '\0'; // terminating zero + tb->buf[tb->length] = '\0'; // terminating zero GlobalUnlock(cbuf); CloseClipboard(); |