On Wed, 29 Sept 2021 at 09:19, Eric Pouech eric.pouech@gmail.com wrote:
to be complete: gcc11 complains with: In function 'unit_vec2', inlined from 'attempt_line_merge' at /home/eric/work/wine/dlls/d3dx9_36/mesh.c:5542:5: /home/eric/work/wine/dlls/d3dx9_36/mesh.c:5511:12: warning: 'lastdir' may be used uninitialized [-Wmaybe-uninitialized] 5511 | return D3DXVec2Normalize(D3DXVec2Subtract(dir, pt2, pt1), dir); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In file included from /home/eric/work/wine/include/d3dx9.h:31, from /home/eric/work/wine/dlls/d3dx9_36/d3dx9_private.h:32, from /home/eric/work/wine/dlls/d3dx9_36/mesh.c:31: /home/eric/work/wine/dlls/d3dx9_36/mesh.c: In function 'attempt_line_merge': /home/eric/work/wine/include/d3dx9math.h:352:21: note: by argument 2 of type 'const D3DXVECTOR2 *' to 'D3DXVec2Normalize' declared here 352 | D3DXVECTOR2* WINAPI D3DXVec2Normalize(D3DXVECTOR2 *pout, const D3DXVECTOR2 *pv); | ^~~~~~~~~~~~~~~~~ /home/eric/work/wine/dlls/d3dx9_36/mesh.c:5527:25: note: 'lastdir' declared here 5527 | D3DXVECTOR2 curdir, lastdir; | ^~~~~~~
as D3DXV2Normalize isn't symetrical in its arguments definition (first arg is const ptr as input, while second arg is ptr as output) so gcc11 complains about passing as first arg (being a const ptr) an uninitialized object (it has no way of knowing that both args are aliased)
I don't think that's exactly what's happening. In particular, note that the message complains about the second argument to D3DXVec2Normalize(), not the first. My guess is that it doesn't notice that the D3DXVec2Subtract() call initialises "dir" before the call to D3DXVec2Normalize() actually happens. That's admittedly a little tricky; the straightforward translation would first push "dir" to the stack, which points to uninitialised memory at that point, then call D3DXVec2Subtract() which initialises the vector pointed to by "dir", push the return value of D3DXVec2Subtract(), and finally call D3DXVec2Normalize().
In any case, I think the change makes things more readable, so in that regard I think it's fine; I'd quibble a little about the commit message. It's up to Matteo to sign off on this patch though.