|
|
Message-ID: <kpaq6m4zbcl5gdtahqwafvd55oohb3aumfbqe5wdmjju5znfbj@2qeoli6wcifg>
Date: Wed, 20 Mar 2024 17:11:16 +0000
From: NRK <nrk@...root.org>
To: Rich Felker <dalias@...c.org>
Cc: Jₑₙₛ Gustedt <jens.gustedt@...ia.fr>,
musl@...ts.openwall.com, Mike Cui <cuicui@...il.com>
Subject: Re: Potential bug in __res_msend_rc() wrt to union
initialization.
> That's simply not true. There is no difference in the rules as
> specified by the standard.
I don't think your assertion is correct, at least it hasn't been
demonstrated.
> ¶19 says:
>
> "all subobjects that are not initialized explicitly shall be
> initialized implicitly the same as objects that have static
> storage duration."
>
> The term "subobject" does not seem to be defined, so there's some
> ambiguity, but I would read ¶19 as applying the above text about
> static unions to automatic ones.
The term subobject might not be clearly defined but there's a strong
indication that it refers to objects contained within an aggregate, and
NOT members of a union. Consider the following case:
struct { int a; int b; } object = { .a = 5 };
Assuming `a` and `b` are subobjects, `a` will be initialized to 5 and
`b` to 0. Which makes sense and is consistent with all existing
implementation I'm aware of. Now consider the same with a union:
union { int a; int b; } object = { .a = 5 };
If `b` is a subobjects then it should be initialized to zero according
to the rule. But that can't happen since that'd overwrite the value of
`a`. This to me is a convincing case that subobjects do not refer to
union members, as there can be only 1 active at a time.
Now I don't agree with clang's decision to not zero the entire union in
case of `{0}`. It's unnecessarily hostile, brings negligible (if any)
gains and *will* be causing bugs (this is the 2nd one I'm witnessing).
But as it currently stands, it's not a wrong interpretation of the
standard either. If the intention was to have no difference between {0}
and {} it has not been written down clearly.
- NRK
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.