Factor out the magic values needed to derive the maximum image data buffer length. If the values need to be changed in the future, the derived value will be automatically recalculated.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48054 Signed-off-by: Jeff Smith whydoubt@gmail.com --- dlls/gdi32/tests/bitmap.c | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c index 8fe160546c..130ef3ca3a 100644 --- a/dlls/gdi32/tests/bitmap.c +++ b/dlls/gdi32/tests/bitmap.c @@ -910,10 +910,18 @@ static void test_dibsections(void) ReleaseDC(0, hdc); }
+#define DATA_WIDTH 2 +#define DATA_HEIGHT 2 +#define MAX_PLANES 64 +#define MAX_BPP 64 +#define DATA_STRIDE_LENGTH (((DATA_WIDTH * MAX_BPP + 31) / 32) * 4) +#define DATA_PLANE_LENGTH (DATA_STRIDE_LENGTH * DATA_HEIGHT) +#define DATA_LENGTH (DATA_PLANE_LENGTH * MAX_PLANES) + static void test_dib_formats(void) { BITMAPINFO *bi; - char data[256]; + char data[DATA_LENGTH]; void *bits; int planes, bpp, compr, format; HBITMAP hdib, hbmp; @@ -928,9 +936,9 @@ static void test_dib_formats(void)
memset( data, 0xaa, sizeof(data) );
- for (bpp = 0; bpp <= 64; bpp++) + for (bpp = 0; bpp <= MAX_BPP; bpp++) { - for (planes = 0; planes <= 64; planes++) + for (planes = 0; planes <= MAX_PLANES; planes++) { for (compr = 0; compr < 8; compr++) { @@ -949,8 +957,8 @@ static void test_dib_formats(void)
memset( bi, 0, sizeof(bi->bmiHeader) ); bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biPlanes = planes; bi->bmiHeader.biBitCount = bpp; bi->bmiHeader.biCompression = compr; @@ -969,8 +977,8 @@ static void test_dib_formats(void) if (!planes) expect_ok = FALSE; memset( bi, 0, sizeof(bi->bmiHeader) ); bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biPlanes = planes; bi->bmiHeader.biBitCount = bpp; bi->bmiHeader.biCompression = compr; @@ -1027,8 +1035,8 @@ static void test_dib_formats(void) bpp, bi->bmiHeader.biBitCount );
bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biPlanes = planes; bi->bmiHeader.biBitCount = bpp; bi->bmiHeader.biCompression = compr; @@ -1067,8 +1075,8 @@ static void test_dib_formats(void)
memset( bi, 0, sizeof(bi->bmiHeader) ); bi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biPlanes = 1; bi->bmiHeader.biBitCount = 16; bi->bmiHeader.biCompression = BI_BITFIELDS; @@ -1120,8 +1128,8 @@ static void test_dib_formats(void) ret = SetDIBits(hdc, hbmp, 0, 1, data, bi, DIB_RGB_COLORS); ok( ret, "SetDIBits failed with bad bitfields\n" );
- bi->bmiHeader.biWidth = -2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = -DATA_HEIGHT; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biBitCount = 32; bi->bmiHeader.biCompression = BI_RGB; hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0); @@ -1144,7 +1152,7 @@ static void test_dib_formats(void) ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with negative width\n" );
bi->bmiHeader.biWidth = 0; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biBitCount = 32; bi->bmiHeader.biCompression = BI_RGB; hdib = CreateDIBSection(hdc, bi, DIB_RGB_COLORS, &bits, NULL, 0); @@ -1167,7 +1175,7 @@ static void test_dib_formats(void) ret = GetDIBits(hdc, hbmp, 0, 2, NULL, bi, DIB_RGB_COLORS); ok( !ret || broken(ret), /* nt4 */ "GetDIBits succeeded with zero width\n" );
- bi->bmiHeader.biWidth = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; bi->bmiHeader.biHeight = 0; bi->bmiHeader.biBitCount = 32; bi->bmiHeader.biCompression = BI_RGB; @@ -1193,8 +1201,8 @@ static void test_dib_formats(void)
/* some functions accept DIB_PAL_COLORS+1, but not beyond */
- bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biBitCount = 1; bi->bmiHeader.biCompression = BI_RGB; hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+1, &bits, NULL, 0); @@ -1217,8 +1225,8 @@ static void test_dib_formats(void) ret = GetDIBits(hdc, hbmp, 0, 0, NULL, bi, DIB_PAL_COLORS+1); ok( !ret, "GetDIBits succeeded with DIB_PAL_COLORS+1\n" );
- bi->bmiHeader.biWidth = 2; - bi->bmiHeader.biHeight = 2; + bi->bmiHeader.biWidth = DATA_WIDTH; + bi->bmiHeader.biHeight = DATA_HEIGHT; bi->bmiHeader.biBitCount = 1; bi->bmiHeader.biCompression = BI_RGB; hdib = CreateDIBSection(hdc, bi, DIB_PAL_COLORS+2, &bits, NULL, 0);
On Fri, Nov 22, 2019 at 01:40:58PM -0600, Jeff Smith wrote:
Factor out the magic values needed to derive the maximum image data buffer length. If the values need to be changed in the future, the derived value will be automatically recalculated.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48054 Signed-off-by: Jeff Smith whydoubt@gmail.com
dlls/gdi32/tests/bitmap.c | 46 +++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 19 deletions(-)
diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c index 8fe160546c..130ef3ca3a 100644 --- a/dlls/gdi32/tests/bitmap.c +++ b/dlls/gdi32/tests/bitmap.c @@ -910,10 +910,18 @@ static void test_dibsections(void) ReleaseDC(0, hdc); }
+#define DATA_WIDTH 2 +#define DATA_HEIGHT 2 +#define MAX_PLANES 64 +#define MAX_BPP 64 +#define DATA_STRIDE_LENGTH (((DATA_WIDTH * MAX_BPP + 31) / 32) * 4) +#define DATA_PLANE_LENGTH (DATA_STRIDE_LENGTH * DATA_HEIGHT) +#define DATA_LENGTH (DATA_PLANE_LENGTH * MAX_PLANES)
static void test_dib_formats(void) { BITMAPINFO *bi;
- char data[256];
- char data[DATA_LENGTH];
I think simply fixing the array size is more appropriate here.
Huw.
On Mon, Nov 25, 2019 at 3:48 AM Huw Davies huw@codeweavers.com wrote:
I think simply fixing the array size is more appropriate here.
Huw.
Hi Huw,
Just to confirm, get rid of ALL of the magic number factoring and ONLY change the array size to the appropriate number (i.e. just the bug fix, no code improvements)? I want make certain to send what you are requesting.
-- Jeff