Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 20 Mar 2024 08:42:47 +0100
From: Aaron Peter Bachmann <aaron_ng@...de.at>
To: Rich Felker <dalias@...c.org>
Cc: musl@...ts.openwall.com
Subject: Re: Potential bug in __res_msend_rc() wrt to union, initialization.

On

19 Mar 2024 17:36:41 -0400, Rich Felker wrote:
> > > actually the introduction of `{}` versus `{0}` in C23 was not meant to
> > > provide any difference in semantics, just to make the syntax nicer and
> > > consistent with C++.
> > 
> > Regardless of what the intention was, the reality is that it *does* have
> > semantic difference. Specifically, empty initialization `{}` benefits
> > from the default initialization rules, which specify zero-ing out the
> > padding bits whereas `{0}` doesn't guarantee that.
>
> That's simply not true. There is no difference in the rules as
> specified by the standard.
There is:
Before C23:
{ } was not mentioned in the std so it was implicitly undefined.
{0} was defined.
=> This is a difference.

C23:
We can look at n3096: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
Later versions not generally available have - to the best of my knowledge -
not changed in regard of whet we are discussing.

6.7.10 p10, p11, ...:
10 Except where explicitly stated otherwise, for the purposes of this subclause unnamed members
of objects of structure and union type do not participate in initialization. Unnamed members of
structure objects have indeterminate representation even after initialization.
11 If an object that has automatic storage duration is not initialized explicitly, its representation is
indeterminate. If an object that has static or thread storage duration is not initialized explicitly, or
any object is initialized with an empty initializer, then it is subject to default initialization, which
initializes an object as follows: ...

For me it reads that when the empty initializer {} is not used,
we have default initialization only for memory with static and thread local storage duration,
but not for automatic storage duration. This affects the padding.
=> This is a difference.

The empty initializer can be used for VLAs.
=> This is a difference. But certainly not one we are discussing.

But it does not matter for musl, as it does not use C23 and it could not reasonably do so.
The fact that compilers implementing {} before C23 could not in advance see what C23 would say
does not help either.
It will take some time before we can benefit from the stronger guarantees C23 provides via {}.

And I would also like to add: If no difference was intended, as we know from Jens,
there had better be no difference.

Regards Aaron Peter Bachmann




Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.