[v2 PATCH] user32/text: Stop crash when Tab Length is zero
Alistair Leslie-Hughes
leslie_alistair at hotmail.com
Tue Mar 1 22:22:10 CST 2016
Signed-off-by: Alistair Leslie-Hughes <leslie_alistair at hotmail.com>
---
dlls/user32/tests/text.c | 39 ++++++++++++++++++++++++++++++++++++++-
dlls/user32/text.c | 2 +-
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/tests/text.c b/dlls/user32/tests/text.c
index df8d3ee..57bc647 100644
--- a/dlls/user32/tests/text.c
+++ b/dlls/user32/tests/text.c
@@ -44,8 +44,9 @@ static void test_DrawTextCalcRect(void)
static WCHAR emptystringW[] = { 0 };
static CHAR wordbreak_text[] = "line1 line2";
static WCHAR wordbreak_textW[] = {'l','i','n','e','1',' ','l','i','n','e','2',0};
+ static char tabstring[] = "one\ttwo";
INT textlen, textheight, heightcheck;
- RECT rect = { 0, 0, 100, 0 };
+ RECT rect = { 0, 0, 100, 0 }, rect2;
BOOL ret;
DRAWTEXTPARAMS dtp;
BOOL conform_xp = TRUE;
@@ -580,6 +581,42 @@ static void test_DrawTextCalcRect(void)
ok(textheight >= heightcheck * 6, "Got unexpected textheight %d, expected at least %d.\n",
textheight, heightcheck * 6);
+ /* DT_TABSTOP | DT_EXPANDTABS tests */
+ SetRect( &rect, 0,0, 10, 10);
+ textheight = DrawTextA(hdc, tabstring, -1, &rect, DT_TABSTOP | DT_EXPANDTABS );
+ ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
+
+ SetRect( &rect, 0,0, 10, 10);
+ memset(&dtp, 0, sizeof(dtp));
+ dtp.cbSize = sizeof(dtp);
+ textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT, &dtp);
+ ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
+ ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
+
+ SetRect( &rect2, 0,0, 10, 10);
+ memset(&dtp, 0, sizeof(dtp));
+ dtp.cbSize = sizeof(dtp);
+ textheight = DrawTextExA(hdc, tabstring, -1, &rect2, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
+ ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
+ ok(dtp.iTabLength == 0, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
+ ok(rect.left == rect2.left && rect.right != rect2.right && rect.top == rect2.top && rect.bottom == rect2.bottom,
+ "incorrect rect %d,%d-%d,%d rect2 %d,%d-%d,%d\n",
+ rect.left, rect.top, rect.right, rect.bottom, rect2.left, rect2.top, rect2.right, rect2.bottom );
+
+ SetRect( &rect, 0,0, 10, 10);
+ memset(&dtp, 0, sizeof(dtp));
+ dtp.cbSize = sizeof(dtp);
+ dtp.iTabLength = 8;
+ textheight = DrawTextExA(hdc, tabstring, -1, &rect, DT_CALCRECT | DT_TABSTOP | DT_EXPANDTABS, &dtp);
+ ok(textheight >= heightcheck, "Got unexpected textheight %d\n", textheight);
+ ok(dtp.iTabLength == 8, "invalid dtp.iTabLength = %i\n",dtp.iTabLength);
+ ok(rect.left == rect2.left, "unexpected value %d, got %d\n", rect.left, rect2.left);
+ /* XP, 2003 appear to not give the same values. */
+ ok(rect.right == rect2.right || broken(rect.right > rect2.right), "unexpected value %d, got %d\n",rect.right, rect2.right);
+ ok(rect.top == rect2.top, "unexpected value %d, got %d\n", rect.top, rect2.top);
+ ok(rect.bottom == rect2.bottom , "unexpected value %d, got %d\n", rect.bottom, rect2.bottom);
+
+
SelectObject(hdc, hOldFont);
ret = DeleteObject(hFont);
ok( ret, "DeleteObject error %u\n", GetLastError());
diff --git a/dlls/user32/text.c b/dlls/user32/text.c
index 7b0302e..2ac3afd 100644
--- a/dlls/user32/text.c
+++ b/dlls/user32/text.c
@@ -948,7 +948,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
if (flags & DT_EXPANDTABS)
{
- int tabstop = ((flags & DT_TABSTOP) && dtp) ? dtp->iTabLength : 8;
+ int tabstop = ((flags & DT_TABSTOP) && dtp && dtp->iTabLength) ? dtp->iTabLength : 8;
tabwidth = tm.tmAveCharWidth * tabstop;
}
--
2.7.0
More information about the wine-patches
mailing list