Re: warning: dereferencing type-punned pointer

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Tatsuo Ishii <ishii(at)postgresql(dot)org>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: warning: dereferencing type-punned pointer
Date: 2024-07-24 17:41:13
Message-ID: 5fc409de-922c-4db2-ab28-6c37ac3a2f0f@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 24.07.24 08:55, Tatsuo Ishii wrote:
> origin.c: In function ‘StartupReplicationOrigin’:
> origin.c:773:16: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
> 773 | file_crc = *(pg_crc32c *) &disk_state;
> | ^~~~~~~~~~~~~~~~~~~~~~~~~

> I am not so sure about StartupReplicationOrigin. Should we fix it now?
> For me the code looks sane as long as we keep -fno-strict-aliasing
> option. Or maybe better to fix so that someday we could remove the
> compiler option?

This is basically the textbook example of aliasing violation, isn't it?
Wouldn't it be just as simple to do

memcpy(&file_crc, &disk_state, sizeof(file_crc));

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2024-07-24 17:45:31 Re: [18] Policy on IMMUTABLE functions and Unicode updates
Previous Message Tom Lane 2024-07-24 17:36:45 Re: Fixing backslash dot for COPY FROM...CSV