[PATCH] dlls/windows.globalization: don't allocate a partial structure

Eric Pouech eric.pouech at gmail.com
Wed Mar 23 02:19:11 CDT 2022


GCC 11 complains about accessing struct hstring_vector (-Warray-bounds)
when the allocation is made for a 0-sized vector

so ensure that we always allocate a memory block to fit a whole
structure

Signed-off-by: Eric Pouech <eric.pouech at gmail.com>

---
 dlls/windows.globalization/main.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/dlls/windows.globalization/main.c b/dlls/windows.globalization/main.c
index 3e5a59bde14..363e0150af1 100644
--- a/dlls/windows.globalization/main.c
+++ b/dlls/windows.globalization/main.c
@@ -213,8 +213,10 @@ static const struct IVectorView_HSTRINGVtbl hstring_vector_vtbl =
 static HRESULT hstring_vector_create(HSTRING *values, SIZE_T count, IVectorView_HSTRING **out)
 {
     struct hstring_vector *impl;
-
-    if (!(impl = malloc(offsetof(struct hstring_vector, values[count])))) return E_OUTOFMEMORY;
+    /* always allocate at least the full structure to avoid GCC11 warnings */
+    if (!(impl = malloc(max(offsetof(struct hstring_vector, values[count]),
+                            sizeof(struct hstring_vector)))))
+        return E_OUTOFMEMORY;
     impl->ref = 1;
 
     impl->IVectorView_HSTRING_iface.lpVtbl = &hstring_vector_vtbl;




More information about the wine-devel mailing list