Bruno Jesus : gdi32: Support negative count values in GetBitmapBits.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Apr 8 10:40:44 CDT 2015


Module: wine
Branch: master
Commit: 5c323a540c2892fdd4ca98e2b51da82a66e30f80
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5c323a540c2892fdd4ca98e2b51da82a66e30f80

Author: Bruno Jesus <00cpxxx at gmail.com>
Date:   Tue Apr  7 23:19:44 2015 -0300

gdi32: Support negative count values in GetBitmapBits.

---

 dlls/gdi32/bitmap.c       |  2 +-
 dlls/gdi32/tests/bitmap.c | 28 ++++++++++++++++++++--------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c
index 79374a0..6d1bed9 100644
--- a/dlls/gdi32/bitmap.c
+++ b/dlls/gdi32/bitmap.c
@@ -253,7 +253,7 @@ LONG WINAPI GetBitmapBits(
     dst_stride = get_bitmap_stride( bmp->dib.dsBm.bmWidth, bmp->dib.dsBm.bmBitsPixel );
     ret = max = dst_stride * bmp->dib.dsBm.bmHeight;
     if (!bits) goto done;
-    if (count > max) count = max;
+    if (count < 0 || count > max) count = max;
     ret = count;
 
     src.visrect.left = 0;
diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c
index 84f843f..e19c552 100644
--- a/dlls/gdi32/tests/bitmap.c
+++ b/dlls/gdi32/tests/bitmap.c
@@ -56,8 +56,9 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE
 {
     BITMAP bm;
     BITMAP bma[2];
-    INT ret, width_bytes;
+    INT ret, width_bytes, i;
     BYTE buf[512], buf_cmp[512];
+    INT test_size[] = {0 /*first value will be changed */, 0, -1, -1000, ~0, sizeof(buf)};
 
     ret = GetObjectW(hbm, sizeof(bm), &bm);
     ok(ret == sizeof(bm), "GetObject returned %d\n", ret);
@@ -75,17 +76,28 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE
     assert(sizeof(buf) == sizeof(buf_cmp));
 
     SetLastError(0xdeadbeef);
-    ret = GetBitmapBits(hbm, 0, NULL);
-    ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
+    test_size[0] = bm.bmWidthBytes * bm.bmHeight;
+    /* NULL output buffer with different count values */
+    for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++)
+    {
+        ret = GetBitmapBits(hbm, test_size[i], NULL);
+        ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
+    }
 
     memset(buf_cmp, 0xAA, sizeof(buf_cmp));
     memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight);
 
-    memset(buf, 0xAA, sizeof(buf));
-    ret = GetBitmapBits(hbm, sizeof(buf), buf);
-    ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight);
-    ok(!memcmp(buf, buf_cmp, sizeof(buf)),
-        "buffers do not match, depth %d\n", bmih->biBitCount);
+    /* Correct output buffer with different count values */
+    for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++)
+    {
+        int expect = i == 1 ? 0 : bm.bmWidthBytes * bm.bmHeight;
+        memset(buf, 0xAA, sizeof(buf));
+        ret = GetBitmapBits(hbm, test_size[i], buf);
+        ok(ret == expect, "Test[%d]: %d != %d\n", i, ret, expect);
+        if (expect)
+            ok(!memcmp(buf, buf_cmp, sizeof(buf)),
+               "Test[%d]: buffers do not match, depth %d\n", i, bmih->biBitCount);
+    }
 
     /* test various buffer sizes for GetObject */
     ret = GetObjectW(hbm, sizeof(*bma) * 2, bma);




More information about the wine-cvs mailing list