[PATCH 06/11] Sptr: avoided potentially undefined behaviour.
andrew at digital-domain.net
Thu Jun 16 15:03:38 UTC 2022
On Thu, 16 Jun 2022 13:35:12 +0300
Max Romanov <max.romanov at gmail.com> wrote:
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.
> This change was made just to shut the cppcheck which warning is a false positive.
So it wasn't just to shut up cppcheck, I already filtered out many
This one was a bit tricky to nail down but between SO, the
C(11) standard and cppcheck I came down on the side of it being UB,
due to thinking that the ordering of the read and write of the two union
members was UB.
So if we're sure that it is indeed OK, then this can simply be dropped.
More information about the unit