<div>I'm appreciate your patience and effort to make it clear!<br/>
<br/>
I also admit it is not obvious way to describe the relocatable offset in C.<br/>
<br/>
--<br/>
Max<br/><br/>-----Original Message-----<br/>From: Alejandro Colomar <alx.manpages@gmail.com><br/>To: Max Romanov <max.romanov@gmail.com>, Andrew Clayton <andrew@digital-domain.net><br/>Cc: unit@nginx.org<br/>Sent: сб, 18 июн. 2022 14:00<br/>Subject: Re: [PATCH 06/11] Sptr: avoided potentially undefined behaviour.<br/><br/></div>Hi Max,
<br/>
<br/>
On 6/18/22 11:39, Max Romanov wrote:
<br/>
<br/>
> The pointer to structure's field does not stored in the structure. And
<br/>
> reading the pointer to the field is just adding an offset to the object
<br/>
> pointer.
<br/>
<br/>
Okay, now I got it.
<br/>
<br/>
So, p->base is reinterpreting as uint_8[], the contents of some stucture.
<br/>
p, the pointer to the union, is really a pointer to that structure.
<br/>
p->base, when used in pointer arithmetics, decays to a pointer to the
<br/>
first element, which is the same as a pointer to the union, which is the
<br/>
same as a pointer to the reinterpreted structure.
<br/>
And p->offset is just an offset to that pointer, so it's the offset of
<br/>
ptr to the start to the structure (reinterpreted as a uint8_t[]), and
<br/>
it's stored as the first element of said structure.
<br/>
<br/>
Now it makes sense.
<br/>
<br/>
So, yes, the patch was wrong, and the linter has a bug (but they'll
<br/>
probably ignore it because unions in C++ are so crap that it doesn't pay
<br/>
out fixing it).
<br/>
<br/>
>
<br/>
> Why do you ignore my suggestion to replace "p->base" with "(uint8_t *)
<br/>
> p"
<br/>
<br/>
Sory, I misunderstood it yesterday.
<br/>
<br/>
> and try to understand the purpose of the object, 'base' and 'offset'?
<br/>
> Instead you digging the specifications to prove the validation software
<br/>
> behavior.
<br/>
<br/>
Thanks!
<br/>
<br/>
Alex
<br/>
<br/>
<br/>
--
<br/>
Alejandro Colomar
<br/>
<<a href="http://www.alejandro-colomar.es">http://www.alejandro-colomar.es</a>/>
<br/>