[PATCH 06/11] Sptr: avoided potentially undefined behaviour.

Alejandro Colomar alx.manpages at gmail.com
Thu Jun 16 15:32:22 UTC 2022


Hi Andrew, and Max,

On 6/16/22 17:03, Andrew Clayton wrote:
> On Thu, 16 Jun 2022 13:35:12 +0300
> Max Romanov <max.romanov at gmail.com> wrote:
> 
>> Hello,
> 
> Thanks for the review!
>   
>> This patch is useless. Please try to understand the structure of sptr_t before made such changes.
> 
> Yes, that union is a bit of a head scratcher! ;)
> 
>> How extra assignment to temporary variable may change undefined behavior to defined?
> 
> The idea was to avoid undefined memory ordering.

Hmmm, AFAIR, `u.a = u.b + 1;` is fine, since the = creates a sequence 
point, isn't it?

<https://stackoverflow.com/a/33291213/6872717>

The only possible problem would be if the union hadn't been initialized, 
but that's a completely different story, and this wouldn't fix it :)

Cheers,

Alex



More information about the unit mailing list