riched20: fix text replacement with text limit

Clinton Stimpson cjstimpson at utwire.net
Sun Mar 25 23:50:39 CDT 2007


This patch fixes bug 6985.

Moved the clearing of previous selections so it is done *before* 
calculating the amount of space available to insert new text, or the new 
text might not be inserted.
Double check that amount of space available doesn't go less than zero 
leading to memory errors.  It is possible to set the text, then set the 
limit to something smaller than the amount of text, then insert new text.

A test is included.

Thanks,
Clinton Stimpson

ChangeLog:
  Fix insertion of text when near/over the text limit.

-------------- next part --------------
Index: dlls/riched20/caret.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/caret.c,v
retrieving revision 1.36
diff -u -r1.36 caret.c
--- dlls/riched20/caret.c	11 Jan 2007 11:35:15 -0000	1.36
+++ dlls/riched20/caret.c	26 Mar 2007 04:40:40 -0000
@@ -431,18 +431,23 @@
 {
   const WCHAR *pos;
   ME_Cursor *p = NULL;
+  int freeSpace;
+  
+  /* FIXME really HERE ? */
+  if (ME_IsSelection(editor))
+    ME_DeleteSelection(editor);
+
   /* FIXME: is this too slow? */
   /* Didn't affect performance for WM_SETTEXT (around 50sec/30K) */
-  int freeSpace = editor->nTextLimit - ME_GetTextLength(editor);
+  freeSpace = editor->nTextLimit - ME_GetTextLength(editor);
+  if(freeSpace < 0) freeSpace = 0;
 
   /* text operations set modified state */
   editor->nModifyStep = 1;
 
   assert(style);
 
-  /* FIXME really HERE ? */
-  if (ME_IsSelection(editor))
-    ME_DeleteSelection(editor);
 
   assert(nCursor>=0 && nCursor<editor->nCursors);
   if (len == -1)
Index: dlls/riched20/tests/editor.c
===================================================================
RCS file: /home/wine/wine/dlls/riched20/tests/editor.c,v
retrieving revision 1.40
diff -u -r1.40 editor.c
--- dlls/riched20/tests/editor.c	21 Mar 2007 22:04:04 -0000	1.40
+++ dlls/riched20/tests/editor.c	26 Mar 2007 04:40:40 -0000
@@ -1019,7 +1019,9 @@
 static void test_EM_EXLIMITTEXT(void)
 {
   int i, selBegin, selEnd, len1, len2;
+  int result;
   char text[1024 + 1];
+  char buffer[1024 + 1];
   int textlimit = 0; /* multiple of 100 */
   HWND hwndRichEdit = new_richedit(NULL);
   
@@ -1087,6 +1089,19 @@
     "EM_EXLIMITTEXT: No Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
     len1,len2,i);
 
+  /* put some long text in, then set the limit smaller than existing text */
+  textlimit = 5;
+  memset(text, 'W', textlimit + 18);
+  text[textlimit + 18] = 0;
+  SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit+18);
+  SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
+  SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
+  SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
+  SendMessage(hwndRichEdit, WM_CHAR, 'A', 1);
+  SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
+  result = strlen(buffer) && buffer[0] == 'A';
+  ok(0 != result, "string must be 'A': string = %s\n", buffer);
+
   DestroyWindow(hwndRichEdit);
 }
 


More information about the wine-patches mailing list