Re: Should we use MemSet or {0} for struct initialization?

Поиск
Список
Период
Сортировка
От Richard Guo
Тема Re: Should we use MemSet or {0} for struct initialization?
Дата
Msg-id CAMbWs4_jAOeTTecM9nVsEpWT7Cghe-T2NVfzeYiV1xhrfVFVgw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Should we use MemSet or {0} for struct initialization?  (John Naylor <john.naylor@enterprisedb.com>)
Список pgsql-hackers

On Thu, Aug 31, 2023 at 7:07 PM John Naylor <john.naylor@enterprisedb.com> wrote:
> On Thu, Aug 31, 2023 at 5:34 PM Richard Guo <guofenglinux@gmail.com> wrote:
> >
> > While working on a bug in expandRecordVariable() I noticed that in the
> > switch statement for case RTE_SUBQUERY we initialize struct ParseState
> > with {0} while for case RTE_CTE we do that with MemSet.  I understand
> > that there is nothing wrong with this, just cannot get away with the
> > inconsistency inside the same function (sorry for the nitpicking).
> >
> > Do we have a preference for how to initialize structures?  From 9fd45870
> > it seems that we prefer to {0}.  So here is a trivial patch doing that.

It seems to have been deliberately left that way in the wake of that commit, see:

https://www.postgresql.org/message-id/87d2e5f8-3c37-d185-4bbc-1de163ac4b10%40enterprisedb.com

(If so, it deserves a comment to keep people from trying to change it...)

Thanks for pointing this out.  Yeah, struct initialization does not work
for some cases with padding bits, such as for a hash key we need to
clear the padding too.

The case in expandRecordVariable() mentioned here should be safe though,
maybe this is an omission from 9fd45870?

Thanks
Richard

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

Предыдущее
От: Nathan Bossart
Дата:
Сообщение: Re: should frontend tools use syncfs() ?
Следующее
От: Andy Fan
Дата:
Сообщение: Re: Extract numeric filed in JSONB more effectively