Commit 5bd304bd authored by Huw Davies's avatar Huw Davies Committed by Alexandre Julliard

gdi32: The text extents functions fail if passed a negative count.

parent 2b1c639f
...@@ -920,9 +920,14 @@ BOOL WINAPI GetTextExtentPoint32A( HDC hdc, LPCSTR str, INT count, ...@@ -920,9 +920,14 @@ BOOL WINAPI GetTextExtentPoint32A( HDC hdc, LPCSTR str, INT count,
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
INT wlen; INT wlen;
LPWSTR p = FONT_mbtowc(hdc, str, count, &wlen, NULL); LPWSTR p;
if (count < 0) return FALSE;
if (p) { p = FONT_mbtowc(hdc, str, count, &wlen, NULL);
if (p)
{
ret = GetTextExtentPoint32W( hdc, p, wlen, size ); ret = GetTextExtentPoint32W( hdc, p, wlen, size );
HeapFree( GetProcessHeap(), 0, p ); HeapFree( GetProcessHeap(), 0, p );
} }
...@@ -975,10 +980,15 @@ BOOL WINAPI GetTextExtentExPointI( HDC hdc, const WORD *indices, INT count, INT ...@@ -975,10 +980,15 @@ BOOL WINAPI GetTextExtentExPointI( HDC hdc, const WORD *indices, INT count, INT
LPINT nfit, LPINT dxs, LPSIZE size ) LPINT nfit, LPINT dxs, LPSIZE size )
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
DC * dc = get_dc_ptr( hdc ); DC *dc;
if (count < 0) return FALSE;
dc = get_dc_ptr( hdc );
if (!dc) return FALSE; if (!dc) return FALSE;
if(dc->gdiFont) { if(dc->gdiFont)
{
ret = WineEngGetTextExtentExPointI(dc->gdiFont, indices, count, max_ext, nfit, dxs, size); ret = WineEngGetTextExtentExPointI(dc->gdiFont, indices, count, max_ext, nfit, dxs, size);
size->cx = abs(INTERNAL_XDSTOWS(dc, size->cx)); size->cx = abs(INTERNAL_XDSTOWS(dc, size->cx));
size->cy = abs(INTERNAL_YDSTOWS(dc, size->cy)); size->cy = abs(INTERNAL_YDSTOWS(dc, size->cy));
...@@ -1052,9 +1062,13 @@ BOOL WINAPI GetTextExtentExPointA( HDC hdc, LPCSTR str, INT count, ...@@ -1052,9 +1062,13 @@ BOOL WINAPI GetTextExtentExPointA( HDC hdc, LPCSTR str, INT count,
INT *walpDx = NULL; INT *walpDx = NULL;
LPWSTR p = NULL; LPWSTR p = NULL;
if (alpDx && if (count < 0) return FALSE;
NULL == (walpDx = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT))))
return FALSE; if (alpDx)
{
walpDx = HeapAlloc( GetProcessHeap(), 0, count * sizeof(INT) );
if (!walpDx) return FALSE;
}
p = FONT_mbtowc(hdc, str, count, &wlen, NULL); p = FONT_mbtowc(hdc, str, count, &wlen, NULL);
ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, lpnFit, walpDx, size); ret = GetTextExtentExPointW( hdc, p, wlen, maxExt, lpnFit, walpDx, size);
...@@ -1118,9 +1132,10 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count, ...@@ -1118,9 +1132,10 @@ BOOL WINAPI GetTextExtentExPointW( HDC hdc, LPCWSTR str, INT count,
TRACE("(%p, %s, %d)\n",hdc,debugstr_wn(str,count),maxExt); TRACE("(%p, %s, %d)\n",hdc,debugstr_wn(str,count),maxExt);
if (count < 0) return FALSE;
dc = get_dc_ptr(hdc); dc = get_dc_ptr(hdc);
if (! dc) if (!dc) return FALSE;
return FALSE;
GetTextMetricsW(hdc, &tm); GetTextMetricsW(hdc, &tm);
......
...@@ -1054,6 +1054,7 @@ static void test_text_extents(void) ...@@ -1054,6 +1054,7 @@ static void test_text_extents(void)
HFONT hfont; HFONT hfont;
SIZE sz; SIZE sz;
SIZE sz1, sz2; SIZE sz1, sz2;
BOOL ret;
memset(&lf, 0, sizeof(lf)); memset(&lf, 0, sizeof(lf));
strcpy(lf.lfFaceName, "Arial"); strcpy(lf.lfFaceName, "Arial");
...@@ -1110,6 +1111,14 @@ static void test_text_extents(void) ...@@ -1110,6 +1111,14 @@ static void test_text_extents(void)
"GetTextExtentExPointW with lpnFit and alpDx both NULL returns incorrect results\n"); "GetTextExtentExPointW with lpnFit and alpDx both NULL returns incorrect results\n");
HeapFree(GetProcessHeap(), 0, extents); HeapFree(GetProcessHeap(), 0, extents);
/* extents functions fail with -ve counts (the interesting case being -1) */
ret = GetTextExtentPointA(hdc, "o", -1, &sz);
ok(ret == FALSE, "got %d\n", ret);
ret = GetTextExtentExPointA(hdc, "o", -1, 0, NULL, NULL, &sz);
ok(ret == FALSE, "got %d\n", ret);
ret = GetTextExtentExPointW(hdc, wt, -1, 0, NULL, NULL, &sz1);
ok(ret == FALSE, "got %d\n", ret);
hfont = SelectObject(hdc, hfont); hfont = SelectObject(hdc, hfont);
DeleteObject(hfont); DeleteObject(hfont);
ReleaseDC(NULL, hdc); ReleaseDC(NULL, hdc);
......
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