GCC11 warns when accessing the fields of a structure, when the allocation of that structure is smaller than the size of the structure
even though the accessed fields are within the boundaries of the memory are that has been allocated
this serie addresses a couple of those
Note to Zebediah: in the quartz one, I wondered if we could reduce the allocated size to a VIDEOINFOHEADER when the dwBitMasks is not used, but I didn't change it
A+ ---
Eric Pouech (6): dlls/oledb32/tests: silence some gcc11 warnings (-Warray-bounds) dlls/windows.globalization: use 0-length array to keep gcc happy gdiplus/tests: get rid of some GCC11 warnings (-Warray-bounds) dlls/quartz: use VIDEOINFOHEADER instead of partially allocated VIDEOINFO structure dlls/gdiplus: get rid of gcc11 warnings (-Warray-bounds) dlls/user32: silence gcc11 warning (-Warray-bounds)
dlls/gdiplus/image.c | 5 ++++- dlls/gdiplus/tests/graphics.c | 19 +++++++++---------- dlls/oledb32/tests/convert.c | 10 +++++----- dlls/quartz/avidec.c | 9 +++++---- dlls/user32/win.c | 2 +- dlls/windows.globalization/main.c | 2 +- 6 files changed, 25 insertions(+), 22 deletions(-)
size of 20 used in most of the tests is not necessarly wrong wrt the fields adressed, even if I don't fully grasp the logic of a 20 byte buffer: - VARIANT is 16 bytes on 32bit systems, and 24 bytes on 64 bit systems - and all the other structures are 16 bytes at most
anyway, make it always of the size of a VARIANT, in order to keep gcc happy
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/oledb32/tests/convert.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/dlls/oledb32/tests/convert.c b/dlls/oledb32/tests/convert.c index 0d888e834e3..7144150c2bc 100644 --- a/dlls/oledb32/tests/convert.c +++ b/dlls/oledb32/tests/convert.c @@ -327,7 +327,7 @@ static void test_converttoi1(void) { HRESULT hr; signed char dst; - BYTE src[20]; + BYTE src[sizeof(VARIANT)]; /* assuming that VARIANT is larger than all the types used in src */ DBSTATUS dst_status; DBLENGTH dst_len; static const WCHAR ten[] = {'1','0',0}; @@ -638,7 +638,7 @@ static void test_converttoi2(void) { HRESULT hr; signed short dst; - BYTE src[20]; + BYTE src[sizeof(VARIANT)]; /* assuming that VARIANT is larger than all the types used in src */ DBSTATUS dst_status; DBLENGTH dst_len; static const WCHAR ten[] = {'1','0',0}; @@ -950,7 +950,7 @@ static void test_converttoi4(void) { HRESULT hr; INT i4; - BYTE src[20]; + BYTE src[sizeof(VARIANT)]; /* assuming that VARIANT is larger than all the types used in src */ DBSTATUS dst_status; DBLENGTH dst_len; static const WCHAR ten[] = {'1','0',0}; @@ -1224,7 +1224,7 @@ static void test_converttoi8(void) { HRESULT hr; LARGE_INTEGER dst; - BYTE src[20]; + BYTE src[sizeof(VARIANT)]; /* assuming that VARIANT is larger than all the types used in src */ DBSTATUS dst_status; DBLENGTH dst_len; static const WCHAR ten[] = {'1','0',0}; @@ -2774,7 +2774,7 @@ static void test_converttoui4(void) { HRESULT hr; DWORD dst; - BYTE src[20]; + BYTE src[sizeof(VARIANT)]; DBSTATUS dst_status; DBLENGTH dst_len;
GCC complains about accessing struct hstring_vector with a too small allocated (-Warray-bounds)
define struct hstring_vector with a 0-length array (which is was the allocation strategy does)
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/windows.globalization/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/windows.globalization/main.c b/dlls/windows.globalization/main.c index e8fcd46ef63..1f9e5ba259d 100644 --- a/dlls/windows.globalization/main.c +++ b/dlls/windows.globalization/main.c @@ -54,7 +54,7 @@ struct hstring_vector LONG ref;
ULONG count; - HSTRING values[1]; + HSTRING values[0]; };
static inline struct hstring_vector *impl_from_IVectorView_HSTRING(IVectorView_HSTRING *iface)
don't pretend using a BITMAPINFO when only a BITMAPINFOHEADER is used
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/gdiplus/tests/graphics.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
diff --git a/dlls/gdiplus/tests/graphics.c b/dlls/gdiplus/tests/graphics.c index 690efa8ac1e..c8c31ce258b 100644 --- a/dlls/gdiplus/tests/graphics.c +++ b/dlls/gdiplus/tests/graphics.c @@ -1313,21 +1313,20 @@ static void test_GdipDrawImagePointsRect(void) GpGraphics *graphics = NULL; GpPointF ptf[4]; GpBitmap *bm = NULL; - BYTE rbmi[sizeof(BITMAPINFOHEADER)]; BYTE buff[400]; - BITMAPINFO *bmi = (BITMAPINFO*)rbmi; + BITMAPINFOHEADER bmihdr; HDC hdc = GetDC( hwnd ); if (!hdc) return;
- memset(rbmi, 0, sizeof(rbmi)); - bmi->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bmi->bmiHeader.biWidth = 10; - bmi->bmiHeader.biHeight = 10; - bmi->bmiHeader.biPlanes = 1; - bmi->bmiHeader.biBitCount = 32; - bmi->bmiHeader.biCompression = BI_RGB; - status = GdipCreateBitmapFromGdiDib(bmi, buff, &bm); + memset(&bmihdr, 0, sizeof(bmihdr)); + bmihdr.biSize = sizeof(BITMAPINFOHEADER); + bmihdr.biWidth = 10; + bmihdr.biHeight = 10; + bmihdr.biPlanes = 1; + bmihdr.biBitCount = 32; + bmihdr.biCompression = BI_RGB; + status = GdipCreateBitmapFromGdiDib((BITMAPINFO*)&bmihdr, buff, &bm); expect(Ok, status); ok(NULL != bm, "Expected bitmap to be initialized\n"); status = GdipCreateFromHDC(hdc, &graphics);
Signed-off-by: Esme Povirk esme@codeweavers.com
this fixes a couple of GCC11 warnings (-Wbounds)
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/quartz/avidec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/quartz/avidec.c b/dlls/quartz/avidec.c index f8660890273..1295e8704df 100644 --- a/dlls/quartz/avidec.c +++ b/dlls/quartz/avidec.c @@ -331,7 +331,7 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter); const VIDEOINFOHEADER *sink_format; - VIDEOINFO *format; + VIDEOINFOHEADER *format;
if (!filter->sink.pin.peer) return VFW_S_NO_MORE_ITEMS; @@ -363,9 +363,10 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
if (IsEqualGUID(formats[index].subtype, &MEDIASUBTYPE_RGB565)) { - format->dwBitMasks[iRED] = 0xf800; - format->dwBitMasks[iGREEN] = 0x07e0; - format->dwBitMasks[iBLUE] = 0x001f; + DWORD *dwBitMasks = (DWORD *)(format + 1); + dwBitMasks[iRED] = 0xf800; + dwBitMasks[iGREEN] = 0x07e0; + dwBitMasks[iBLUE] = 0x001f; mt->cbFormat = offsetof(VIDEOINFO, dwBitMasks[3]); } else
On 2/14/22 03:28, Eric Pouech wrote:
this fixes a couple of GCC11 warnings (-Wbounds)
Signed-off-by: Eric Pouech eric.pouech@gmail.com
dlls/quartz/avidec.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/dlls/quartz/avidec.c b/dlls/quartz/avidec.c index f8660890273..1295e8704df 100644 --- a/dlls/quartz/avidec.c +++ b/dlls/quartz/avidec.c @@ -331,7 +331,7 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
struct avi_decompressor *filter = impl_from_strmbase_filter(iface->filter); const VIDEOINFOHEADER *sink_format;
- VIDEOINFO *format;
VIDEOINFOHEADER *format;
if (!filter->sink.pin.peer) return VFW_S_NO_MORE_ITEMS;
@@ -363,9 +363,10 @@ static HRESULT avi_decompressor_source_get_media_type(struct strmbase_pin *iface
if (IsEqualGUID(formats[index].subtype, &MEDIASUBTYPE_RGB565)) {
format->dwBitMasks[iRED] = 0xf800;
format->dwBitMasks[iGREEN] = 0x07e0;
format->dwBitMasks[iBLUE] = 0x001f;
DWORD *dwBitMasks = (DWORD *)(format + 1);
dwBitMasks[iRED] = 0xf800;
dwBitMasks[iGREEN] = 0x07e0;
dwBitMasks[iBLUE] = 0x001f; mt->cbFormat = offsetof(VIDEOINFO, dwBitMasks[3]); } else
I don't think this is an improvement.
I also don't get the warning with gcc 11.2.0. How exactly are you compiling and with which version?
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/gdiplus/image.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c index a7297047308..73736d65ca3 100644 --- a/dlls/gdiplus/image.c +++ b/dlls/gdiplus/image.c @@ -4107,6 +4107,8 @@ static GpStatus decode_image_tiff(IStream* stream, GpImage **image) return decode_image_wic(stream, &GUID_ContainerFormatTiff, NULL, image); }
+C_ASSERT(offsetof(WmfPlaceableFileHeader, Key) == 0); + static GpStatus load_wmf(IStream *stream, GpMetafile **metafile) { WmfPlaceableFileHeader pfh; @@ -4123,7 +4125,8 @@ static GpStatus load_wmf(IStream *stream, GpMetafile **metafile) if (hr != S_OK || size != sizeof(mh)) return GenericError;
- if (((WmfPlaceableFileHeader *)&mh)->Key == WMF_PLACEABLE_KEY) + /* detect whether stream starts with a WmfPlaceablefileheader */ + if (*(UINT32 *)&mh == WMF_PLACEABLE_KEY) { seek.QuadPart = 0; hr = IStream_Seek(stream, seek, STREAM_SEEK_SET, NULL);
Signed-off-by: Esme Povirk esme@codeweavers.com
Signed-off-by: Eric Pouech eric.pouech@gmail.com
--- dlls/user32/win.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 70c3521ab1d..e7200871bef 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -640,7 +640,7 @@ static RECT *CDECL offscreen_window_surface_get_bounds( struct window_surface *b static void *CDECL offscreen_window_surface_get_bitmap_info( struct window_surface *base, BITMAPINFO *info ) { struct offscreen_window_surface *impl = impl_from_window_surface( base ); - memcpy( info, &impl->info, offsetof( BITMAPINFO, bmiColors[0] ) ); + info->bmiHeader = impl->info.bmiHeader; return impl->bits; }