hw/xwin: Fix an issue in winSetSpansNativeGDI() identifed by -Warray-bounds
The BITMAPINFO local only has room for a single RBGQUAD in bmiColors, but we access two (black and white for a mono-color DIB). Fix by changing to a dynamic allocation big enough for a BITMAPINFO and a RGBQUAD. Signed-off-by: Jon TURNEY <jon.turney@dronecode.org.uk> Reviewed-by: Colin Harrison <colin.harrison@virgin.net> Reviewed-by: Marc Haesen <marha@users.sourceforge.net>
This commit is contained in:
parent
784c006adb
commit
4bfb2dce5e
|
@ -46,7 +46,7 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
PixmapPtr pPixmap = NULL;
|
PixmapPtr pPixmap = NULL;
|
||||||
winPrivPixmapPtr pPixmapPriv = NULL;
|
winPrivPixmapPtr pPixmapPriv = NULL;
|
||||||
HBITMAP hbmpOrig = NULL;
|
HBITMAP hbmpOrig = NULL;
|
||||||
BITMAPINFO bmi;
|
BITMAPINFO *pbmi;
|
||||||
HRGN hrgn = NULL, combined = NULL;
|
HRGN hrgn = NULL, combined = NULL;
|
||||||
int nbox;
|
int nbox;
|
||||||
BoxPtr pbox;
|
BoxPtr pbox;
|
||||||
|
@ -57,6 +57,8 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
if (!nbox)
|
if (!nbox)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
pbmi = malloc(sizeof(BITMAPINFO) + sizeof(RGBQUAD));
|
||||||
|
|
||||||
combined = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
|
combined = CreateRectRgn(pbox->x1, pbox->y1, pbox->x2, pbox->y2);
|
||||||
nbox--;
|
nbox--;
|
||||||
pbox++;
|
pbox++;
|
||||||
|
@ -86,19 +88,20 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
"failed on pPixmapPriv->hBitmap\n");
|
"failed on pPixmapPriv->hBitmap\n");
|
||||||
|
|
||||||
while (iSpans--) {
|
while (iSpans--) {
|
||||||
ZeroMemory(&bmi, sizeof(BITMAPINFO));
|
ZeroMemory(pbmi, sizeof(BITMAPINFO));
|
||||||
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
bmi.bmiHeader.biWidth = *piWidths;
|
pbmi->bmiHeader.biWidth = *piWidths;
|
||||||
bmi.bmiHeader.biHeight = 1;
|
pbmi->bmiHeader.biHeight = 1;
|
||||||
bmi.bmiHeader.biPlanes = 1;
|
pbmi->bmiHeader.biPlanes = 1;
|
||||||
bmi.bmiHeader.biBitCount = pDrawable->depth;
|
pbmi->bmiHeader.biBitCount = pDrawable->depth;
|
||||||
bmi.bmiHeader.biCompression = BI_RGB;
|
pbmi->bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
/* Setup color table for mono DIBs */
|
/* Setup color table for mono DIBs */
|
||||||
if (pDrawable->depth == 1) {
|
if (pDrawable->depth == 1) {
|
||||||
bmi.bmiColors[1].rgbBlue = 255;
|
RGBQUAD *bmiColors = &(pbmi->bmiColors[0]);
|
||||||
bmi.bmiColors[1].rgbGreen = 255;
|
bmiColors[1].rgbBlue = 255;
|
||||||
bmi.bmiColors[1].rgbRed = 255;
|
bmiColors[1].rgbGreen = 255;
|
||||||
|
bmiColors[1].rgbRed = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
StretchDIBits(pGCPriv->hdcMem,
|
StretchDIBits(pGCPriv->hdcMem,
|
||||||
|
@ -107,7 +110,7 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
0, 0,
|
0, 0,
|
||||||
*piWidths, 1,
|
*piWidths, 1,
|
||||||
pSrcs,
|
pSrcs,
|
||||||
(BITMAPINFO *) &bmi,
|
(BITMAPINFO *) pbmi,
|
||||||
DIB_RGB_COLORS, g_copyROP[pGC->alu]);
|
DIB_RGB_COLORS, g_copyROP[pGC->alu]);
|
||||||
|
|
||||||
pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
|
pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
|
||||||
|
@ -129,19 +132,20 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
combined = NULL;
|
combined = NULL;
|
||||||
|
|
||||||
while (iSpans--) {
|
while (iSpans--) {
|
||||||
ZeroMemory(&bmi, sizeof(BITMAPINFO));
|
ZeroMemory(pbmi, sizeof(BITMAPINFO));
|
||||||
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
bmi.bmiHeader.biWidth = *piWidths;
|
pbmi->bmiHeader.biWidth = *piWidths;
|
||||||
bmi.bmiHeader.biHeight = 1;
|
pbmi->bmiHeader.biHeight = 1;
|
||||||
bmi.bmiHeader.biPlanes = 1;
|
pbmi->bmiHeader.biPlanes = 1;
|
||||||
bmi.bmiHeader.biBitCount = pDrawable->depth;
|
pbmi->bmiHeader.biBitCount = pDrawable->depth;
|
||||||
bmi.bmiHeader.biCompression = BI_RGB;
|
pbmi->bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
/* Setup color table for mono DIBs */
|
/* Setup color table for mono DIBs */
|
||||||
if (pDrawable->depth == 1) {
|
if (pDrawable->depth == 1) {
|
||||||
bmi.bmiColors[1].rgbBlue = 255;
|
RGBQUAD *bmiColors = &(pbmi->bmiColors[0]);
|
||||||
bmi.bmiColors[1].rgbGreen = 255;
|
bmiColors[1].rgbBlue = 255;
|
||||||
bmi.bmiColors[1].rgbRed = 255;
|
bmiColors[1].rgbGreen = 255;
|
||||||
|
bmiColors[1].rgbRed = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
StretchDIBits(pGCPriv->hdc,
|
StretchDIBits(pGCPriv->hdc,
|
||||||
|
@ -150,7 +154,7 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
0, 0,
|
0, 0,
|
||||||
*piWidths, 1,
|
*piWidths, 1,
|
||||||
pSrcs,
|
pSrcs,
|
||||||
(BITMAPINFO *) &bmi,
|
(BITMAPINFO *) pbmi,
|
||||||
DIB_RGB_COLORS, g_copyROP[pGC->alu]);
|
DIB_RGB_COLORS, g_copyROP[pGC->alu]);
|
||||||
|
|
||||||
pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
|
pSrcs += PixmapBytePad(*piWidths, pDrawable->depth);
|
||||||
|
@ -166,4 +170,6 @@ winSetSpansNativeGDI(DrawablePtr pDrawable,
|
||||||
FatalError("\nwinSetSpansNativeGDI - Unknown drawable type\n\n");
|
FatalError("\nwinSetSpansNativeGDI - Unknown drawable type\n\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(pbmi);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue