gdi32: Add sanity checks for brush hatch styles.

This commit is contained in:
Alexandre Julliard 2011-12-30 11:02:57 +01:00
parent 8bf48557ef
commit ee89ce2982
3 changed files with 46 additions and 0 deletions

View file

@ -149,7 +149,15 @@ BOOL store_brush_pattern( LOGBRUSH *brush, struct brush_pattern *pattern )
{
case BS_SOLID:
case BS_HOLLOW:
return TRUE;
case BS_HATCHED:
if (brush->lbHatch > HS_DIAGCROSS)
{
if (brush->lbHatch >= HS_API_MAX) return FALSE;
brush->lbStyle = BS_SOLID;
brush->lbHatch = 0;
}
return TRUE;
case BS_PATTERN8X8:

View file

@ -79,6 +79,42 @@ static void test_solidbrush(void)
}
}
static void test_hatch_brush(void)
{
int i, size;
HBRUSH brush;
LOGBRUSH lb;
for (i = 0; i < 20; i++)
{
SetLastError( 0xdeadbeef );
brush = CreateHatchBrush( i, RGB(12,34,56) );
if (i < HS_API_MAX)
{
ok( brush != 0, "%u: CreateHatchBrush failed err %u\n", i, GetLastError() );
size = GetObject( brush, sizeof(lb), &lb );
ok( size == sizeof(lb), "wrong size %u\n", size );
ok( lb.lbColor == RGB(12,34,56), "wrong color %08x\n", lb.lbColor );
if (i <= HS_DIAGCROSS)
{
ok( lb.lbStyle == BS_HATCHED, "wrong style %u\n", lb.lbStyle );
ok( lb.lbHatch == i, "wrong hatch %lu/%u\n", lb.lbHatch, i );
}
else
{
ok( lb.lbStyle == BS_SOLID, "wrong style %u\n", lb.lbStyle );
ok( lb.lbHatch == 0, "wrong hatch %lu\n", lb.lbHatch );
}
DeleteObject( brush );
}
else
{
ok( !brush, "%u: CreateHatchBrush succeeded\n", i );
ok( GetLastError() == 0xdeadbeef, "wrong error %u\n", GetLastError() );
}
}
}
static void test_pattern_brush(void)
{
char buffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD) + 32 * 32 / 8];
@ -310,6 +346,7 @@ static void test_palette_brush(void)
START_TEST(brush)
{
test_solidbrush();
test_hatch_brush();
test_pattern_brush();
test_palette_brush();
}

View file

@ -526,6 +526,7 @@ typedef LOGBRUSH PATTERN, *PPATTERN, *LPPATTERN;
#define HS_BDIAGONAL 3
#define HS_CROSS 4
#define HS_DIAGCROSS 5
#define HS_API_MAX 12
/* Fonts */