Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56135
-- v2: wing32: Avoid crash in WinGGetDIBPointer when called with NULL bitmap info. wing32: Add tests.
From: Bernhard Übelacker bernhardu@mailbox.org
--- configure.ac | 1 + dlls/wing32/Makefile.in | 1 + dlls/wing32/tests/Makefile.in | 5 +++ dlls/wing32/tests/wing32.c | 64 +++++++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 dlls/wing32/tests/Makefile.in create mode 100644 dlls/wing32/tests/wing32.c
diff --git a/configure.ac b/configure.ac index cba55126869..9488b3263cc 100644 --- a/configure.ac +++ b/configure.ac @@ -3257,6 +3257,7 @@ WINE_CONFIG_MAKEFILE(dlls/winex11.drv) WINE_CONFIG_MAKEFILE(dlls/winexinput.sys) WINE_CONFIG_MAKEFILE(dlls/wing.dll16,enable_win16) WINE_CONFIG_MAKEFILE(dlls/wing32) +WINE_CONFIG_MAKEFILE(dlls/wing32/tests) WINE_CONFIG_MAKEFILE(dlls/winhttp) WINE_CONFIG_MAKEFILE(dlls/winhttp/tests) WINE_CONFIG_MAKEFILE(dlls/wininet) diff --git a/dlls/wing32/Makefile.in b/dlls/wing32/Makefile.in index 833e62e8d8e..e4da7836632 100644 --- a/dlls/wing32/Makefile.in +++ b/dlls/wing32/Makefile.in @@ -1,4 +1,5 @@ MODULE = wing32.dll +IMPORTLIB = wing32 IMPORTS = user32 gdi32
SOURCES = \ diff --git a/dlls/wing32/tests/Makefile.in b/dlls/wing32/tests/Makefile.in new file mode 100644 index 00000000000..395a9f4706a --- /dev/null +++ b/dlls/wing32/tests/Makefile.in @@ -0,0 +1,5 @@ +TESTDLL = wing32.dll +IMPORTS = wing32 gdi32 + +SOURCES = \ + wing32.c diff --git a/dlls/wing32/tests/wing32.c b/dlls/wing32/tests/wing32.c new file mode 100644 index 00000000000..1a3c958ff02 --- /dev/null +++ b/dlls/wing32/tests/wing32.c @@ -0,0 +1,64 @@ +/* + * Unit test suite for wing32 functions + * + * Copyright 2024 Bernhard Übelacker + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <windows.h> + +#include "wine/test.h" + +HDC WINAPI WinGCreateDC(void); +HBITMAP WINAPI WinGCreateBitmap(HDC, BITMAPINFO*, void **); +void* WINAPI WinGGetDIBPointer(HBITMAP, BITMAPINFO*); + +static void test_WinGGetDIBPointer(void) +{ + HDC dc; + BITMAPINFO bmi; + void *bits; + HBITMAP bmp; + void* dib; + + dc = WinGCreateDC(); + ok(dc != NULL, "WinGCreateDC failed\n"); + + memset(&bmi, 0, sizeof(bmi)); + bmi.bmiHeader.biSize = sizeof(bmi.bmiHeader); + bmi.bmiHeader.biWidth = 1; + bmi.bmiHeader.biHeight = 1; + bmi.bmiHeader.biPlanes = 1; + bmi.bmiHeader.biBitCount= 24; + bmi.bmiHeader.biCompression= BI_RGB; + bmi.bmiHeader.biSizeImage = 0; + bmp = WinGCreateBitmap(dc, &bmi, &bits); + ok(bmp != NULL, "WinGCreateBitmap failed\n"); + + dib = WinGGetDIBPointer(NULL, NULL); + ok(dib == NULL, "WinGGetDIBPointer returned unexpected value %p\n", dib); + + dib = WinGGetDIBPointer(bmp, &bmi); + ok(dib != NULL, "WinGGetDIBPointer failed\n"); + + DeleteObject(bmp); + DeleteDC(dc); +} + +START_TEST(wing32) +{ + test_WinGGetDIBPointer(); +}
From: Bernhard Übelacker bernhardu@mailbox.org
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56135 --- dlls/wing32/tests/wing32.c | 3 +++ dlls/wing32/wing32.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/wing32/tests/wing32.c b/dlls/wing32/tests/wing32.c index 1a3c958ff02..e3f01ff22bc 100644 --- a/dlls/wing32/tests/wing32.c +++ b/dlls/wing32/tests/wing32.c @@ -51,6 +51,9 @@ static void test_WinGGetDIBPointer(void) dib = WinGGetDIBPointer(NULL, NULL); ok(dib == NULL, "WinGGetDIBPointer returned unexpected value %p\n", dib);
+ dib = WinGGetDIBPointer(bmp, NULL); + ok(dib != NULL, "WinGGetDIBPointer failed\n"); + dib = WinGGetDIBPointer(bmp, &bmi); ok(dib != NULL, "WinGGetDIBPointer failed\n");
diff --git a/dlls/wing32/wing32.c b/dlls/wing32/wing32.c index b6702ba8017..14012206286 100644 --- a/dlls/wing32/wing32.c +++ b/dlls/wing32/wing32.c @@ -72,7 +72,7 @@ void * WINAPI WinGGetDIBPointer( HBITMAP hbmp, BITMAPINFO *bmi )
if (GetObjectW( hbmp, sizeof(ds), &ds ) == sizeof(ds)) { - bmi->bmiHeader = ds.dsBmih; + if (bmi) bmi->bmiHeader = ds.dsBmih; return ds.dsBm.bmBits; } return NULL;
On Sun Jan 14 09:36:01 2024 +0000, Zebediah Figura wrote:
Can we have a test for this?
Thanks for having a look. I hoped to get away without test because this module had not yet a tests subdirectory.
Pushed v2 which adds tests to the module.
Those tests don't actually prove this change correct.
Those tests don't actually prove this change correct.
Eh, never mind, I can't read.