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

Alejandro Colomar alx.manpages at gmail.com
Sat Jun 18 14:07:51 UTC 2022

On 6/18/22 16:04, Andrew Clayton wrote:
> 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!

I strongly prefer not having comments about how code works.
They tend to be obsolete, and maintaining comments is harder than the code.

Better improve the code, adding these details to the commit log, where 
the comment is tied to the point in time where it was true, forever.



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

More information about the unit mailing list