[1/2] gdi32: Add a test for minimal acceptable DEVMODEA size, make it pass under Wine

Dmitry Timoshkov dmitry at codeweavers.com
Thu Dec 20 00:49:59 CST 2007


Hello,

the app in the bug 10799 passes an invalid DEVMODEA (dmSize == 0) to
ChangeDisplaySettings, this test shows that GdiConvertToDevmodeW fails to
convert such a DEVMODEA structure and returns NULL.

Changelog:
    [1/2] gdi32: Add a test for minimal acceptable DEVMODEA size, make it
    pass under Wine.
---
 dlls/gdi32/driver.c   |    5 +++++
 dlls/gdi32/tests/dc.c |   13 +++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/dlls/gdi32/driver.c b/dlls/gdi32/driver.c
index a2aa033..31810b0 100644
--- a/dlls/gdi32/driver.c
+++ b/dlls/gdi32/driver.c
@@ -414,6 +414,11 @@ DEVMODEW * WINAPI GdiConvertToDevmodeW(const DEVMODEA *dmA)
     WORD dmW_size, dmA_size;
 
     dmA_size = dmA->dmSize;
+
+    /* this is the minimal dmSize that XP accepts */
+    if (dmA_size < FIELD_OFFSET(DEVMODEA, dmFields))
+        return NULL;
+
     if (dmA_size > sizeof(DEVMODEA))
         dmA_size = sizeof(DEVMODEA);
 
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 60b6ad7..01cb064 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -222,6 +222,19 @@ static void test_GdiConvertToDevmodeW(void)
        "expected %04x, got %04x\n",
         FIELD_OFFSET(DEVMODEW, dmPanningHeight) + sizeof(dmW->dmPanningHeight), dmW->dmSize);
     HeapFree(GetProcessHeap(), 0, dmW);
+
+    SetLastError(0xdeadbeef);
+    dmA.dmSize = 0;
+    dmW = pGdiConvertToDevmodeW(&dmA);
+    ok(!dmW, "GdiConvertToDevmodeW should fail\n");
+    ok(GetLastError() == 0xdeadbeef, "expected 0xdeadbeef, got %u\n", GetLastError());
+
+    /* this is the minimal dmSize that XP accepts */
+    dmA.dmSize = FIELD_OFFSET(DEVMODEA, dmFields);
+    dmW = pGdiConvertToDevmodeW(&dmA);
+    ok(dmW->dmSize == FIELD_OFFSET(DEVMODEW, dmFields),
+       "expected %04x, got %04x\n", FIELD_OFFSET(DEVMODEW, dmFields), dmW->dmSize);
+    HeapFree(GetProcessHeap(), 0, dmW);
 }
 
 START_TEST(dc)
-- 
1.5.3.7






More information about the wine-patches mailing list