Commit 35c8f15b authored by Fabian Maurer's avatar Fabian Maurer Committed by Alexandre Julliard

user32: Ignore invalid parameters in DrawTextEx when HDC is invalid.

parent 9f9f799a
......@@ -519,6 +519,38 @@ static void test_DrawTextCalcRect(void)
ok(textheight==0,"Got textheight from DrawTextExW\n");
ok(dtp.uiLengthDrawn==1337, "invalid dtp.uiLengthDrawn = %i\n",dtp.uiLengthDrawn);
}
/* When passing invalid DC, other parameters must be ignored - no crashes on invalid pointers */
SetLastError(0xdeadbeef);
textheight = DrawTextExW((HDC)0xdeadbeef, emptystringW, 100000, (LPRECT)0xdeadbeef, 0, 0);
ok(textheight == 0, "Got textheight from DrawTextExW\n");
ok(GetLastError() == 0xdeadbeef,"Got error %lu\n", GetLastError());
SetLastError(0xdeadbeef);
textheight = DrawTextExW((HDC)0xdeadbeef, (LPWSTR)0xdeadbeef, 100000, &rect, 0, 0);
ok(textheight == 0, "Got textheight from DrawTextExW\n");
ok(GetLastError() == 0xdeadbeef,"Got error %lu\n", GetLastError());
SetLastError(0xdeadbeef);
textheight = DrawTextExW((HDC)0xdeadbeef, 0, -1, (LPRECT)0xdeadbeef, DT_CALCRECT, 0);
ok(textheight == 0, "Got textheight from DrawTextExW\n");
ok(GetLastError() == 0xdeadbeef,"Got error %lu\n", GetLastError());
SetLastError(0xdeadbeef);
textheight = DrawTextExA((HDC)0xdeadbeef, emptystring, 100000, (LPRECT)0xdeadbeef, 0, 0);
ok(textheight == 0, "Got textheight from DrawTextExA\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_HANDLE,"Got error %lu\n", GetLastError());
SetLastError(0xdeadbeef);
textheight = DrawTextExA((HDC)0xdeadbeef, 0, -1, (LPRECT)0xdeadbeef, DT_CALCRECT, 0);
ok(textheight == 0, "Got textheight from DrawTextExA\n");
ok(GetLastError() == ERROR_INVALID_PARAMETER || GetLastError() == ERROR_INVALID_HANDLE,"Got error %lu\n", GetLastError());
if (0)
{
/* Crashes */
textheight = DrawTextExA((HDC)0xdeadbeef, (LPSTR)0xdeadbeef, 100, &rect, 0, 0);
}
}
/* More test cases from bug 12226 */
......
......@@ -874,8 +874,7 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
int len, lh, count=i_count;
TEXTMETRICW tm;
int lmargin = 0, rmargin = 0;
int x = rect->left, y = rect->top;
int width = rect->right - rect->left;
int x, y, width;
int max_width = 0;
int last_line;
int tabwidth /* to keep gcc happy */ = 0;
......@@ -897,7 +896,13 @@ INT WINAPI DrawTextExW( HDC hdc, LPWSTR str, INT i_count,
if (flags & DT_SINGLELINE)
flags &= ~DT_WORDBREAK;
GetTextMetricsW(hdc, &tm);
if (!GetTextMetricsW(hdc, &tm))
return 0;
x = rect->left;
y = rect->top;
width = rect->right - rect->left;
if (flags & DT_EXTERNALLEADING)
lh = tm.tmHeight + tm.tmExternalLeading;
else
......@@ -1086,18 +1091,24 @@ INT WINAPI DrawTextExA( HDC hdc, LPSTR str, INT count,
DWORD wmax;
DWORD amax;
UINT cp;
TEXTMETRICA tm;
if (!GetTextMetricsA(hdc, &tm))
{
SetLastError(ERROR_INVALID_HANDLE);
return 0;
}
if (!count) return 0;
if (!str && count > 0) return 0;
if( !str || ((count == -1) && !(count = strlen(str))))
{
int lh;
TEXTMETRICA tm;
if (dtp && dtp->cbSize != sizeof(DRAWTEXTPARAMS))
return 0;
GetTextMetricsA(hdc, &tm);
if (flags & DT_EXTERNALLEADING)
lh = tm.tmHeight + tm.tmExternalLeading;
else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment