From: Fabian Maurer Subject: [PATCH v3 2/3] user32: For monochrome icon, use color table to avoid undefined behavior Message-Id: <20210911183947.66609-2-dark.shadow4@web.de> Date: Sat, 11 Sep 2021 20:39:46 +0200 In-Reply-To: <20210911183947.66609-1-dark.shadow4@web.de> References: <20210911183947.66609-1-dark.shadow4@web.de> This fixes a regression from db2b266c57b73e1a16785213ce923b749c84400e. The same function is already used and tested in the previous patch. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=51296 Signed-off-by: Fabian Maurer --- dlls/user32/cursoricon.c | 24 +++++++++++++----------- dlls/user32/tests/cursoricon.c | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c index dc831db9287..cc7219f39d0 100644 --- a/dlls/user32/cursoricon.c +++ b/dlls/user32/cursoricon.c @@ -1559,19 +1559,21 @@ static HBITMAP create_masked_bitmap( int width, int height, const void *and, con { HDC dc = CreateCompatibleDC( 0 ); HBITMAP bitmap; - - const BITMAPINFO bitmap_info = - { - .bmiHeader.biSize = sizeof(BITMAPINFOHEADER), - .bmiHeader.biWidth = width, - .bmiHeader.biHeight = height * 2, - .bmiHeader.biPlanes = 1, - .bmiHeader.biBitCount = 1, - }; + char buffer[sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD) * 2] = {0}; + + BITMAPINFO *bitmap_info = (BITMAPINFO*)buffer; + bitmap_info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); + bitmap_info->bmiHeader.biWidth = width; + bitmap_info->bmiHeader.biHeight = height * 2; + bitmap_info->bmiHeader.biPlanes = 1; + bitmap_info->bmiHeader.biBitCount = 1; + bitmap_info->bmiColors[1].rgbRed = 255; + bitmap_info->bmiColors[1].rgbGreen = 255; + bitmap_info->bmiColors[1].rgbBlue = 255; bitmap = CreateBitmap( width, height * 2, 1, 1, NULL ); - SetDIBits( dc, bitmap, 0, height, and, &bitmap_info, FALSE ); - SetDIBits( dc, bitmap, height, height, xor, &bitmap_info, FALSE ); + SetDIBits( dc, bitmap, 0, height, and, bitmap_info, FALSE ); + SetDIBits( dc, bitmap, height, height, xor, bitmap_info, FALSE ); DeleteDC( dc ); return bitmap; } diff --git a/dlls/user32/tests/cursoricon.c b/dlls/user32/tests/cursoricon.c index 1f9a81e6d0a..68e4f5320ff 100644 --- a/dlls/user32/tests/cursoricon.c +++ b/dlls/user32/tests/cursoricon.c @@ -3140,7 +3140,7 @@ static void check_monochrome_icon(HICON icon, int draw_flag, int line, BOOL todo { COLORREF color = GetPixel(dc, i, 8); int expect = i % 2 == 0 ? 0 : 0xFFFFFF; - todo_wine_if(todo && (i%2 != 0)) + todo_wine_if(todo && (i%2 != 1)) ok_(__FILE__,line)(color == expect, "At index %d got %x\n", i, color); } DeleteObject(canvas); -- 2.33.0