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

Andrew Clayton andrew at digital-domain.net
Sat Jun 18 14:04:45 UTC 2022

On Sat, 18 Jun 2022 13:00:46 +0200
Alejandro Colomar <alx.manpages at gmail.com> wrote:

> So, p->base is reinterpreting as uint_8[], the contents of some stucture.
> p, the pointer to the union, is really a pointer to that structure.
> p->base, when used in pointer arithmetics, decays to a pointer to the 
> first element, which is the same as a pointer to the union, which is the 
> same as a pointer to the reinterpreted structure.
> And p->offset is just an offset to that pointer, so it's the offset of 
> ptr to the start to the structure (reinterpreted as a uint8_t[]), and 
> it's stored as the first element of said structure.

Ugh, that code definitely needs a comment!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://mailman.nginx.org/pipermail/unit/attachments/20220618/6a0530aa/attachment.bin>

More information about the unit mailing list