dwrite: Fix parameter validation in CreateTextLayout()/CreateGdiCompatibleTextLayout().

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2016-01-28 04:17:15 +03:00 committed by Alexandre Julliard
parent edf003771b
commit 8485fa64ca
3 changed files with 41 additions and 2 deletions

View File

@ -4282,6 +4282,9 @@ HRESULT create_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFormat *forma
*ret = NULL;
if (!format || !str)
return E_INVALIDARG;
layout = heap_alloc(sizeof(struct dwrite_textlayout));
if (!layout) return E_OUTOFMEMORY;
@ -4300,6 +4303,9 @@ HRESULT create_gdicompat_textlayout(const WCHAR *str, UINT32 len, IDWriteTextFor
*ret = NULL;
if (!format || !str)
return E_INVALIDARG;
layout = heap_alloc(sizeof(struct dwrite_textlayout));
if (!layout) return E_OUTOFMEMORY;

View File

@ -1045,9 +1045,9 @@ static HRESULT WINAPI dwritefactory_CreateTextLayout(IDWriteFactory2 *iface, WCH
UINT32 len, IDWriteTextFormat *format, FLOAT max_width, FLOAT max_height, IDWriteTextLayout **layout)
{
struct dwritefactory *This = impl_from_IDWriteFactory2(iface);
TRACE("(%p)->(%s:%u %p %f %f %p)\n", This, debugstr_wn(string, len), len, format, max_width, max_height, layout);
if (!format) return E_INVALIDARG;
return create_textlayout(string, len, format, max_width, max_height, layout);
}
@ -1060,7 +1060,6 @@ static HRESULT WINAPI dwritefactory_CreateGdiCompatibleTextLayout(IDWriteFactory
TRACE("(%p)->(%s:%u %p %f %f %f %p %d %p)\n", This, debugstr_wn(string, len), len, format, layout_width, layout_height,
pixels_per_dip, transform, use_gdi_natural, layout);
if (!format) return E_INVALIDARG;
return create_gdicompat_textlayout(string, len, format, layout_width, layout_height, pixels_per_dip, transform,
use_gdi_natural, layout);
}

View File

@ -728,25 +728,44 @@ static void test_CreateTextLayout(void)
factory = create_factory();
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 0.0, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1.0, 0.0, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 0.0, 1.0, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
DWRITE_FONT_STRETCH_NORMAL, 10.0, enusW, &format);
ok(hr == S_OK, "got 0x%08x\n", hr);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateTextLayout(factory, NULL, 0, format, 100.0f, 100.0f, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
hr = IDWriteFactory_CreateTextLayout(factory, strW, 0, format, 0.0f, 0.0f, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
IDWriteTextLayout_Release(layout);
EXPECT_REF(format, 1);
hr = IDWriteFactory_CreateTextLayout(factory, strW, 6, format, 1000.0, 1000.0, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
@ -823,20 +842,30 @@ static void test_CreateGdiCompatibleTextLayout(void)
factory = create_factory();
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 0.0, 0.0, 0.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 0.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1.0, 0.0, 1.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, NULL, 1000.0, 1000.0, 1.0, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
/* create with text format */
hr = IDWriteFactory_CreateTextFormat(factory, tahomaW, NULL, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL,
@ -844,6 +873,11 @@ static void test_CreateGdiCompatibleTextLayout(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
EXPECT_REF(format, 1);
layout = (void*)0xdeadbeef;
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, NULL, 0, format, 100.0f, 100.0f, 1.0f, NULL, FALSE, &layout);
ok(hr == E_INVALIDARG, "got 0x%08x\n", hr);
ok(layout == NULL, "got %p\n", layout);
hr = IDWriteFactory_CreateGdiCompatibleTextLayout(factory, strW, 6, format, 100.0, 100.0, 1.0, NULL, FALSE, &layout);
ok(hr == S_OK, "got 0x%08x\n", hr);
EXPECT_REF(format, 1);