From 784c006adb22c6693ad30dd0b1b05369cfaa7b5e Mon Sep 17 00:00:00 2001 From: Jon TURNEY Date: Sat, 10 Aug 2013 11:55:23 +0100 Subject: [PATCH] hw/xwin: Fix -Warray-bounds warning in winXCursorToHCURSOR() Rewrite winXCursorToHCURSOR() so access to BITMAPINFO bmiColors member doesn't trigger an -Warray-bounds warning. Note that the underlying storage is allocated as a BITMAPV4HEADER, so has sufficent room for the extra RGBQUADs bmiColors after the BITMAPINFO bmiHeader. wincursor.c: In function 'winSetCursor': wincursor.c:293:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:294:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:295:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:296:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:297:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:298:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:299:24: error: array subscript is above array bounds [-Werror=array-bounds] wincursor.c:300:24: error: array subscript is above array bounds [-Werror=array-bounds] Signed-off-by: Jon TURNEY Reviewed-by: Colin Harrison Reviewed-by: Marc Haesen --- hw/xwin/wincursor.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hw/xwin/wincursor.c b/hw/xwin/wincursor.c index 2962d06ad..285e1bcc2 100644 --- a/hw/xwin/wincursor.c +++ b/hw/xwin/wincursor.c @@ -273,9 +273,12 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen) } /* End if-truecolor-icon */ if (!lpBits) { + RGBQUAD *pbmiColors; /* Bicolor, use a palettized DIB */ WIN_DEBUG_MSG("winLoadCursor: Trying two color cursor\n"); pbmi = (BITMAPINFO *) &bi; + pbmiColors = &(pbmi->bmiColors[0]); + memset(pbmi, 0, sizeof(BITMAPINFOHEADER)); pbmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); pbmi->bmiHeader.biWidth = pScreenPriv->cursor.sm_cx; @@ -286,18 +289,19 @@ winLoadCursor(ScreenPtr pScreen, CursorPtr pCursor, int screen) pbmi->bmiHeader.biSizeImage = 0; pbmi->bmiHeader.biClrUsed = 3; pbmi->bmiHeader.biClrImportant = 3; - pbmi->bmiColors[0].rgbRed = 0; /* Empty */ - pbmi->bmiColors[0].rgbGreen = 0; - pbmi->bmiColors[0].rgbBlue = 0; - pbmi->bmiColors[0].rgbReserved = 0; - pbmi->bmiColors[1].rgbRed = pCursor->backRed >> 8; /* Background */ - pbmi->bmiColors[1].rgbGreen = pCursor->backGreen >> 8; - pbmi->bmiColors[1].rgbBlue = pCursor->backBlue >> 8; - pbmi->bmiColors[1].rgbReserved = 0; - pbmi->bmiColors[2].rgbRed = pCursor->foreRed >> 8; /* Foreground */ - pbmi->bmiColors[2].rgbGreen = pCursor->foreGreen >> 8; - pbmi->bmiColors[2].rgbBlue = pCursor->foreBlue >> 8; - pbmi->bmiColors[2].rgbReserved = 0; + + pbmiColors[0].rgbRed = 0; /* Empty */ + pbmiColors[0].rgbGreen = 0; + pbmiColors[0].rgbBlue = 0; + pbmiColors[0].rgbReserved = 0; + pbmiColors[1].rgbRed = pCursor->backRed >> 8; /* Background */ + pbmiColors[1].rgbGreen = pCursor->backGreen >> 8; + pbmiColors[1].rgbBlue = pCursor->backBlue >> 8; + pbmiColors[1].rgbReserved = 0; + pbmiColors[2].rgbRed = pCursor->foreRed >> 8; /* Foreground */ + pbmiColors[2].rgbGreen = pCursor->foreGreen >> 8; + pbmiColors[2].rgbBlue = pCursor->foreBlue >> 8; + pbmiColors[2].rgbReserved = 0; lpBits = (unsigned long *) calloc(pScreenPriv->cursor.sm_cx *