On Tuesday 03 December 2024 16:27:15 Martin Storsjö wrote:
> On Tue, 3 Dec 2024, Martin Storsjö wrote:
> 
> > On Wed, 27 Nov 2024, Pali Rohár wrote:
> > 
> > > Explicitly initialize variable to zeros, which has same effect as
> > > initialzing it via memset.
> > > ---
> > > mingw-w64-crt/crt/crt_handler.c | 8 ++------
> > > 1 file changed, 2 insertions(+), 6 deletions(-)
> > 
> > LGTM, pushed. Thanks!
> 
> On second thought - technically, this doesn't have the exact same behaviour.
> If __mingw_init_ehandler would be called multiple times, there could be a
> reason for calling memset() explicitly.

It is not visible in the diff, but the functions starts with

  int
  __mingw_init_ehandler (void)
  {
    static int was_here = 0;
    size_t e = 0;
    PIMAGE_SECTION_HEADER pSec;
    PBYTE _ImageBase = _GetPEImageBase ();

    if (was_here || !_ImageBase)
      return was_here;
    was_here = 1;
    ...

which prevents multiple calls. So I think that it should have the same
behavior.

> (And even without the {} added here,
> IIRC static variables are guaranteed to be zero initialized - they aren't
> uninitialized like local variables.)

Yes, that is truth, this change is not needed. I wanted to make it
visible that they are zero initialized. Feel free to drop this part of
the change.

The behavior is different only for global variables, they are affected
by gcc -fcommon/-fno-common options. So for global variables it is a
good idea to always initialize them explicitly.

> But anyway, in practice __mingw_init_ehandler is only called once in each
> image, so this point is moot.
> 
> // Martin


_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to