Re: warning: dereferencing type-punned pointer

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: warning: dereferencing type-punned pointer
Дата
Msg-id 5fc409de-922c-4db2-ab28-6c37ac3a2f0f@eisentraut.org
обсуждение исходный текст
Ответ на warning: dereferencing type-punned pointer  (Tatsuo Ishii <ishii@postgresql.org>)
Ответы Re: warning: dereferencing type-punned pointer
Список 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));




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Fixing backslash dot for COPY FROM...CSV
Следующее
От: Jeff Davis
Дата:
Сообщение: Re: [18] Policy on IMMUTABLE functions and Unicode updates