Re: [HACKERS] Small fix: avoid passing null pointers to memcpy()

From: didier <did447(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [HACKERS] Small fix: avoid passing null pointers to memcpy()
Date: 2019-05-26 07:41:23
Message-ID: CAJRYxu+YdYjTeT6=EG3Gi7RwtyL_XS5b7FaJNwtZCGHvRL1-gA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, May 24, 2019 at 6:35 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2019-05-26 08:45:55 Re: Read-only access to temp tables for 2PC transactions
Previous Message Fabien COELHO 2019-05-26 06:35:30 Re: Why does pg_checksums -r not have a long option?