summaryrefslogtreecommitdiff
path: root/win32.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-04-06 19:11:41 +0000
committerDarkvater <darkvater@openttd.org>2006-04-06 19:11:41 +0000
commitb68b9b149a5a0c969de94f192420d953c14b1109 (patch)
tree0c757bee941699bbd6bd6b5291cf2d22688471e2 /win32.c
parent558ecb16317bccb53e534f561c659844bcd89df5 (diff)
downloadopenttd-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.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/win32.c b/win32.c
index 0a83c66fe..321597283 100644
--- a/win32.c
+++ b/win32.c
@@ -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();