Re: [HACKERS] Small fix: avoid passing null pointers to memcpy() - Mailing list pgsql-hackers

From didier
Subject Re: [HACKERS] Small fix: avoid passing null pointers to memcpy()
Date
Msg-id CAJRYxu+YdYjTeT6=EG3Gi7RwtyL_XS5b7FaJNwtZCGHvRL1-gA@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] Small fix: avoid passing null pointers to memcpy()  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi,

On Fri, May 24, 2019 at 6:35 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:


> These seem to be down to use of AnyArrayType:
>
> typedef union AnyArrayType
> {
>         ArrayType       flt;
>         ExpandedArrayHeader xpn;
> } AnyArrayType;
>
> ASAN seems to believe that use of this union entitles the compiler to
> assume 8-byte alignment even when touching fields of a short-header

In my understanding  union has to be aligned to ExpandedArrayHeader (8
bytes) or it's a UB.

On x64 it could be an issue if AnyArrayType alignment is less than 4,
sse is enable and suddenly compiler choose to use sse instructions
with 16 bytes requirement then compiler may not emit the right code.

It's not rhetorical, big surprise first time you get a SIGBUS signal,
or a SIGFPE doing integer math, on x64.

Regards
Didier



pgsql-hackers by date:

Previous
From: Fabien COELHO
Date:
Subject: Re: Why does pg_checksums -r not have a long option?
Next
From: Simon Riggs
Date:
Subject: Re: Read-only access to temp tables for 2PC transactions