mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Mike Cui <cuicui@gmail.com>
Cc: NRK <nrk@disroot.org>, musl@lists.openwall.com
Subject: Re: [musl] Potential bug in __res_msend_rc() wrt to union initialization.
Date: Tue, 19 Mar 2024 11:42:22 -0400	[thread overview]
Message-ID: <20240319154222.GK4163@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAMbjb13m8_+FHRfOV5M3ff6nf1iT=2Rk4mzom55FZArqAYUEdA@mail.gmail.com>

On Tue, Mar 19, 2024 at 08:04:31AM -0700, Mike Cui wrote:
> On Tue, Mar 19, 2024 at 6:18 AM Rich Felker <dalias@libc.org> wrote:
> 
> > On Mon, Mar 18, 2024 at 05:01:41PM -0700, Mike Cui wrote:
> > > Yeah I also just went over the C99 spec as well, section 6.7.8, and I
> > have
> > > to agree with clang developer's interpretation, that "{ 0 }"
> > > only initializes the first member of the union.
> >
> > There is no such thing as "only initializes [part]" in the C language.
> > The { 0 } *only provides a value for* the first member. The question
> > is about what happens to parts of the object for which the initializer
> > did not "provide a value". However, the C99 standard does not clearly
> > describe how the bits of a union that are not part of the member for
> > which a value is provided (usually the first, unless a designated
> > initializer is used) are filled on initialization.
> >
> > You are referring to this paragraph?
> 
> 6.7.9 ¶21
> If there are fewer initializers in a brace-enclosed list than there are
> elements or members of an aggregate, or fewer characters in a string
> literal used to initialize an array of known size than there are elements
> in the array, the remainder of the aggregate shall be initialized
> implicitly the same as objects that have static storage duration.
> 
> Folks on the LLVM discourse pointed out this paragraph does not apply to
> unions, since unions are not "aggegates" according to the definition in
> 6.2.5p21:
> 21. Arithmetic types and pointer types are collectively called scalar
> types. Array and structure types are collectively called *aggregate* types.

No, the part below that you didn't reply to covers unions:

> > C11 adds (in 6.7.9 ¶10):
> >
> >     "if it is a union, the first named member is initialized
> >     (recursively) according to these rules, and any padding is
> >     initialized to zero bits;"
> >
> > where C99 just had (6.7.8):
> >
> >     "if it is a union, the first named member is initialized
> >     (recursively) according to these rules."
> >
> > So I think C11 and later actually require the full zero
> > initialization of all bits, and clang is just wrong.
> >
> > > "{ }" apparently is added in C23 as the "universal zero initializer". So
> > > changing the order moving sin6 up is the only way to be C99 conformant.
> >
> > Indeed since at the source level we just depend on C99 not C11, this
> > should be changed. But clang needs to be fixed too.
> >
> > Rich
> >

  reply	other threads:[~2024-03-19 15:42 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-18 19:56 Mike Cui
2024-03-18 21:34 ` Rich Felker
2024-03-18 22:22   ` NRK
2024-03-18 22:39     ` [musl] Potential bug in __res_msend_rc() wrt to union initialisation Thorsten Glaser
2024-03-19  0:01     ` [musl] Potential bug in __res_msend_rc() wrt to union initialization Mike Cui
2024-03-19 13:18       ` Rich Felker
2024-03-19 15:04         ` Mike Cui
2024-03-19 15:42           ` Rich Felker [this message]
2024-03-19 15:55             ` Mike Cui
2024-03-19 16:08               ` Rich Felker
2024-03-19 16:39                 ` Jₑₙₛ Gustedt
2024-03-19 20:47                   ` Thorsten Glaser
2024-03-21 10:58                     ` Jₑₙₛ Gustedt
2024-03-21 16:41                       ` Thorsten Glaser
2024-03-19 21:04                   ` NRK
2024-03-19 21:36                     ` Rich Felker
2024-03-20 17:11                       ` 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=20240319154222.GK4163@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=cuicui@gmail.com \
    --cc=musl@lists.openwall.com \
    --cc=nrk@disroot.org \
    /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).