Fix for RichEdit out of space error in DAoC

Rob Crittenden <[email protected]> Tue, 13 Feb 2007 23:41:15 -0500
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------010601070305020203000506
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

With the latest patch to DAoC a RichEdit out of space dialog pops up and 
clicking Ok lets the program continue but the display is blank. 
According to the MSDN it should truncate the string.

Attached is a patch to do just that. I've only tested it with DAoC and 
it seems to work as expected (it truncates the string).

I release this patch under the X11 license. Do what you will with it.

rob

--------------010601070305020203000506
Content-Type: text/x-patch;
 name="edit.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="edit.patch"

Index: controls/edit.c
===================================================================
RCS file: /cvsroot/winex/controls/edit.c,v
retrieving revision 1.5
diff -u -r1.5 edit.c
--- controls/edit.c	18 Feb 2004 22:27:35 -0000	1.5
+++ controls/edit.c	14 Feb 2007 03:37:45 -0000
@@ -1819,12 +1819,7 @@
 
 	if (size <= es->buffer_size)
 		return TRUE;
-	if (size > es->buffer_limit) {
-		EDIT_NOTIFY_PARENT(hwnd, es, EN_MAXTEXT, "EN_MAXTEXT");
-		return FALSE;
-	}
-	if (size > es->buffer_limit)
-		size = es->buffer_limit;
+        /* No need to check (size > es->buffer_limit), already done. */
 
 	TRACE("trying to ReAlloc to %d+1 characters\n", size);
 
@@ -2993,20 +2988,32 @@
 	UINT s;
 	UINT e;
 	UINT i;
+	UINT nl;
 	LPWSTR p;
 	HRGN hrgn = 0;
 
-	TRACE("%s, can_undo %d, send_update %d\n",
-	    debugstr_w(lpsz_replace), can_undo, send_update);
-
 	s = es->selection_start;
 	e = es->selection_end;
 
+	TRACE("%s, can_undo %d, send_update %d, strl %d, tl %d, s %d, e %d\n",
+	    debugstr_w(lpsz_replace), can_undo, send_update, strl, tl, s, e);
+
 	if ((s == e) && !strl)
 		return;
 
 	ORDER_UINT(s, e);
 
+        nl = tl - (e - s) + strl;
+
+        /* If the new length is bigger than our buffer then per the MSDN
+         * truncate to fit. We still need to notify the app that the
+         * buffer is full (presumably so it stops sending stuff).
+         */
+        if (nl > es->buffer_limit) {
+		strl = es->buffer_limit - (tl - (e - s));
+		EDIT_NOTIFY_PARENT(hwnd, es, EN_MAXTEXT, "EN_MAXTEXT");
+        }
+
 	if (!EDIT_MakeFit(hwnd, es, tl - (e - s) + strl))
 		return;
 

--------------010601070305020203000506--