mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Aaron Peter Bachmann <aaron_ng@inode.at>
To: Rich Felker <dalias@libc.org>
Cc: musl@lists.openwall.com
Subject: [musl] Re: Potential bug in __res_msend_rc() wrt to union, initialization.
Date: Wed, 20 Mar 2024 08:42:47 +0100	[thread overview]
Message-ID: <71bbc801-cc8a-422b-9db8-3c2029b9b99c@inode.at> (raw)
In-Reply-To: <20240319161925.GM4163@brightrain.aerifal.cx>

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





  reply	other threads:[~2024-03-20  7:43 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-19 11:18 [musl] c23 memset_explicit() Aaron Peter Bachmann
2024-03-19 13:50 ` Jₑₙₛ Gustedt
2024-03-19 14:02   ` Rich Felker
2024-03-19 14:24     ` Jₑₙₛ Gustedt
2024-03-19 15:51     ` Aaron Peter Bachmann
2024-03-19 16:19       ` Rich Felker
2024-03-20  7:42         ` Aaron Peter Bachmann [this message]
2024-03-19 16:37     ` NRK

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=71bbc801-cc8a-422b-9db8-3c2029b9b99c@inode.at \
    --to=aaron_ng@inode.at \
    --cc=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).