Alex Villacís Lasso : riched20: EM_SETCHARFORMAT must return 0, not assert, on invalid struct size.
Alexandre Julliard
julliard at winehq.org
Thu Sep 27 09:27:20 CDT 2007
Module: wine
Branch: master
Commit: be5105e8941bb82254fc3e878ef60f8eaca300c9
URL: http://source.winehq.org/git/wine.git/?a=commit;h=be5105e8941bb82254fc3e878ef60f8eaca300c9
Author: Alex Villacís Lasso <a_villacis at palosanto.com>
Date: Wed Sep 26 12:58:24 2007 -0500
riched20: EM_SETCHARFORMAT must return 0, not assert, on invalid struct size.
---
dlls/riched20/editor.c | 1 +
dlls/riched20/style.c | 3 +-
dlls/riched20/tests/editor.c | 75 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/dlls/riched20/editor.c b/dlls/riched20/editor.c
index f90c353..4efaa90 100644
--- a/dlls/riched20/editor.c
+++ b/dlls/riched20/editor.c
@@ -1732,6 +1732,7 @@ static LRESULT RichEditWndProc_common(HWND hWnd, UINT msg, WPARAM wParam,
CHARFORMAT2W buf, *p;
BOOL bRepaint = TRUE;
p = ME_ToCF2W(&buf, (CHARFORMAT2W *)lParam);
+ if (p == NULL) return 0;
if (!wParam || (editor->mode & TM_PLAINTEXT))
ME_SetDefaultCharFormat(editor, p);
else if (wParam == (SCF_WORD | SCF_SELECTION))
diff --git a/dlls/riched20/style.c b/dlls/riched20/style.c
index 48e29b5..0530c42 100644
--- a/dlls/riched20/style.c
+++ b/dlls/riched20/style.c
@@ -60,8 +60,7 @@ CHARFORMAT2W *ME_ToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
return to;
}
- assert(from->cbSize >= sizeof(CHARFORMAT2W));
- return from;
+ return (from->cbSize >= sizeof(CHARFORMAT2W)) ? from : NULL;
}
void ME_CopyToCF2W(CHARFORMAT2W *to, CHARFORMAT2W *from)
diff --git a/dlls/riched20/tests/editor.c b/dlls/riched20/tests/editor.c
index 7a092c3..416c803 100644
--- a/dlls/riched20/tests/editor.c
+++ b/dlls/riched20/tests/editor.c
@@ -333,6 +333,80 @@ static void test_EM_SCROLLCARET(void)
DestroyWindow(hwndRichEdit);
}
+static void test_EM_SETCHARFORMAT(void)
+{
+ HWND hwndRichEdit = new_richedit(NULL);
+ CHARFORMAT2 cf2;
+ int rc = 0;
+
+ /* Invalid flags, CHARFORMAT2 structure blanked out */
+ memset(&cf2, 0, sizeof(cf2));
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) 0xfffffff0,
+ (LPARAM) &cf2);
+ ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure blanked out */
+ memset(&cf2, 0, sizeof(cf2));
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_DEFAULT,
+ (LPARAM) &cf2);
+ ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure blanked out */
+ memset(&cf2, 0, sizeof(cf2));
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION,
+ (LPARAM) &cf2);
+ ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure blanked out */
+ memset(&cf2, 0, sizeof(cf2));
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_WORD,
+ (LPARAM) &cf2);
+ ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure blanked out */
+ memset(&cf2, 0, sizeof(cf2));
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL,
+ (LPARAM) &cf2);
+ ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
+
+ /* Invalid flags, CHARFORMAT2 structure minimally filled */
+ memset(&cf2, 0, sizeof(cf2));
+ cf2.cbSize = sizeof(CHARFORMAT2);
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) 0xfffffff0,
+ (LPARAM) &cf2);
+ ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure minimally filled */
+ memset(&cf2, 0, sizeof(cf2));
+ cf2.cbSize = sizeof(CHARFORMAT2);
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_DEFAULT,
+ (LPARAM) &cf2);
+ ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure minimally filled */
+ memset(&cf2, 0, sizeof(cf2));
+ cf2.cbSize = sizeof(CHARFORMAT2);
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION,
+ (LPARAM) &cf2);
+ ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure minimally filled */
+ memset(&cf2, 0, sizeof(cf2));
+ cf2.cbSize = sizeof(CHARFORMAT2);
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_WORD,
+ (LPARAM) &cf2);
+ ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+ /* A valid flag, CHARFORMAT2 structure minimally filled */
+ memset(&cf2, 0, sizeof(cf2));
+ cf2.cbSize = sizeof(CHARFORMAT2);
+ rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL,
+ (LPARAM) &cf2);
+ ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
+
+ DestroyWindow(hwndRichEdit);
+}
+
static void test_EM_SETTEXTMODE(void)
{
HWND hwndRichEdit = new_richedit(NULL);
@@ -2125,6 +2199,7 @@ START_TEST( editor )
test_EM_SCROLLCARET();
test_EM_SCROLL();
test_WM_SETTEXT();
+ test_EM_SETCHARFORMAT();
test_EM_SETTEXTMODE();
test_TM_PLAINTEXT();
test_EM_SETOPTIONS();
More information about the wine-cvs
mailing list