Lei Zhang : riched20: Fix for EM_FINDTEXT input validation.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Feb 21 05:04:28 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 0014e50465ee40861ccbdc0dcc054dceafdb2790
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=0014e50465ee40861ccbdc0dcc054dceafdb2790

Author: Lei Zhang <leiz at ucla.edu>
Date:   Mon Feb 20 10:35:14 2006 -0800

riched20: Fix for EM_FINDTEXT input validation.
Fixed the cpMin/cpMax validation code for EM_FINDTEXT.
Removed todo flag from affected EM_FINDTEXT tests.

---

 dlls/riched20/editor.c       |   26 ++++++++++++++++++--------
 dlls/riched20/tests/editor.c |   10 +++++-----
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index 4028468..e7b7fec 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -778,18 +778,28 @@ ME_FindText(ME_TextEditor *editor, DWORD
   if (flags & ~(FR_DOWN | FR_MATCHCASE))
     FIXME("Flags 0x%08lx not implemented\n", flags & ~(FR_DOWN | FR_MATCHCASE));
 
+  nMin = chrg->cpMin;
   if (chrg->cpMax == -1)
-  {
-    nMin = chrg->cpMin;
     nMax = ME_GetTextLength(editor);
-  }
   else
-  {
-    nMin = min(chrg->cpMin, chrg->cpMax);
-    nMax = max(chrg->cpMin, chrg->cpMax);
-  }
+    nMax = chrg->cpMax;
   
-  if (!nLen || nMin < 0 || nMax < 0)
+  /* when searching up, if cpMin < cpMax, then instead of searching
+   * on [cpMin,cpMax], we search on [0,cpMin], otherwise, search on
+   * [cpMax, cpMin]
+   */
+  if (!(flags & FR_DOWN))
+  {
+    int nSwap = nMax;
+
+    nMax = nMin;
+    if (nMin < nSwap)
+      nMin = 0;
+    else
+      nMin = nSwap;
+  }
+
+  if (!nLen || nMin < 0 || nMax < 0 || nMax < nMin)
   {
     if (chrgText)
       chrgText->cpMin = chrgText->cpMax = -1;
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index aa4d1d4..874aee9 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -71,8 +71,8 @@ struct find_s find_tests2[] = {
   {24, 31, "Wine", FR_DOWN | FR_MATCHCASE, 27, 0},
 
   /* Find backwards */
-  {19, 20, "Wine", FR_MATCHCASE, 13, 1},
-  {10, 20, "Wine", FR_MATCHCASE, 4, 1},
+  {19, 20, "Wine", FR_MATCHCASE, 13, 0},
+  {10, 20, "Wine", FR_MATCHCASE, 4, 0},
   {20, 10, "Wine", FR_MATCHCASE, 13, 0},
 
   /* Case-insensitive */
@@ -80,7 +80,7 @@ struct find_s find_tests2[] = {
   {1, 31, "Wine", FR_DOWN, 4, 0},
 
   /* High-to-low ranges */
-  {20, 5, "Wine", FR_DOWN, -1, 1},
+  {20, 5, "Wine", FR_DOWN, -1, 0},
   {2, 1, "Wine", FR_DOWN, -1, 0},
   {30, 29, "Wine", FR_DOWN, -1, 0},
   {20, 5, "Wine", 0, 13, 0},
@@ -110,8 +110,8 @@ struct find_s find_tests2[] = {
 
   /* The backwards case of bug 4479; bounds look right
    * Fails because backward find is wrong */
-  {19, 20, "WINE", FR_MATCHCASE, 0, 1},
-  {0, 20, "WINE", FR_MATCHCASE, -1, 1}
+  {19, 20, "WINE", FR_MATCHCASE, 0, 0},
+  {0, 20, "WINE", FR_MATCHCASE, -1, 0}
 };
 
 static void check_EM_FINDTEXT(HWND hwnd, char *name, struct find_s *f, int id) {




More information about the wine-cvs mailing list