<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Le 23/03/2022 à 11:15, Rémi Bernon a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:cef33a6f-0822-2cd2-68e6-f73930b11bc2@codeweavers.com">On
3/23/22 08:19, Eric Pouech wrote:
<br>
<blockquote type="cite">GCC 11 complains about accessing struct
hstring_vector (-Warray-bounds)
<br>
when the allocation is made for a 0-sized vector
<br>
<br>
so ensure that we always allocate a memory block to fit a whole
<br>
structure
<br>
<br>
Signed-off-by: Eric Pouech <a class="moz-txt-link-rfc2396E" href="mailto:eric.pouech@gmail.com"><eric.pouech@gmail.com></a>
<br>
<br>
---
<br>
dlls/windows.globalization/main.c | 6 ++++--
<br>
1 file changed, 4 insertions(+), 2 deletions(-)
<br>
<br>
diff --git a/dlls/windows.globalization/main.c
b/dlls/windows.globalization/main.c
<br>
index 3e5a59bde14..363e0150af1 100644
<br>
--- a/dlls/windows.globalization/main.c
<br>
+++ b/dlls/windows.globalization/main.c
<br>
@@ -213,8 +213,10 @@ static const struct IVectorView_HSTRINGVtbl
hstring_vector_vtbl =
<br>
static HRESULT hstring_vector_create(HSTRING *values, SIZE_T
count, IVectorView_HSTRING **out)
<br>
{
<br>
struct hstring_vector *impl;
<br>
-
<br>
- if (!(impl = malloc(offsetof(struct hstring_vector,
values[count])))) return E_OUTOFMEMORY;
<br>
+ /* always allocate at least the full structure to avoid
GCC11 warnings */
<br>
+ if (!(impl = malloc(max(offsetof(struct hstring_vector,
values[count]),
<br>
+ sizeof(struct hstring_vector)))))
<br>
+ return E_OUTOFMEMORY;
<br>
impl->ref = 1;
<br>
impl->IVectorView_HSTRING_iface.lpVtbl =
&hstring_vector_vtbl;
<br>
<br>
<br>
</blockquote>
<br>
IMHO GCC should fix its warning instead, we do that in many places
and I think it's completely valid.
<br>
</blockquote>
<p><font face="Helvetica, Arial, sans-serif">Hi Rémi</font></p>
<p><font face="Helvetica, Arial, sans-serif">see
<a class="moz-txt-link-freetext" href="https://www.winehq.org/pipermail/wine-devel/2022-February/thread.html#207795">https://www.winehq.org/pipermail/wine-devel/2022-February/thread.html#207795</a>
for a previous discussion on a similar issue (and the final
decision of over-allocating)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">to my understanding,
accessing through a pointer of type mytype* a memory block which
storage is strictly smaller to sizeo(mytype) is clearly
undefined behavior (I'm not stating that it does in fact
generate wrong results)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">(even if the accessed
field is inside the allocated memory size)</font></p>
<p><font face="Helvetica, Arial, sans-serif">in this precise case,
defining the structure with 0 length array would be another
option, yet non portable</font></p>
<p><font face="Helvetica, Arial, sans-serif">and for the record,
gcc12 (even if non yet released) generates a few more warnings
about this subject on wine code (and I'm not even talking of
mingw port of gcc12)<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif">A+<br>
</font></p>
<p><font face="Helvetica, Arial, sans-serif"></font><br>
</p>
</body>
</html>