Re: Should we use MemSet or {0} for struct initialization? - Mailing list pgsql-hackers

From John Naylor
Subject Re: Should we use MemSet or {0} for struct initialization?
Date
Msg-id CAFBsxsEyj1nU96+_Gk0qHwt_Fe7ainRhKzX4ktU6PrnqM-EP2w@mail.gmail.com
Whole thread Raw
In response to Re: Should we use MemSet or {0} for struct initialization?  (Jelte Fennema <postgres@jeltef.nl>)
Responses Re: Should we use MemSet or {0} for struct initialization?
Re: Should we use MemSet or {0} for struct initialization?
List pgsql-hackers

On Fri, Sep 1, 2023 at 7:48 PM Jelte Fennema <postgres@jeltef.nl> wrote:

> The C standard says:
> > When a value is stored in an object of structure or union type, including in a member object, the bytes of the object representation that correspond to any padding bytes take unspecified values.
>
> So if you set any of the fields after a MemSet, the values of the
> padding bytes that were set to 0 are now unspecified. It seems much
> safer to actually spell out the padding fields of a hash key.

No, the standard is telling you why you need to memset if consistency of padding bytes matters.

--
John Naylor
EDB: http://www.enterprisedb.com

pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Re: Fix a typo in decode.c
Next
From: Chapman Flack
Date:
Subject: Re: Should we use MemSet or {0} for struct initialization?