Re: define pg_structiszero(addr, s, r) - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: define pg_structiszero(addr, s, r)
Date
Msg-id 3023d29e-0fe7-4bec-9028-7f3c0102e437@eisentraut.org
Whole thread Raw
Responses Re: define pg_structiszero(addr, s, r)
List pgsql-hackers
On 18.09.24 06:16, Bertrand Drouvot wrote:
> +#define pg_structiszero(addr, s, r)                                    \
> +    do {                                                            \
> +        /* We assume this initializes to zeroes */                    \
> +        static const s all_zeroes;                                    \
> +        r = (memcmp(addr, &all_zeroes, sizeof(all_zeroes)) == 0);    \
> +    } while (0)

This assumption is kind of the problem, isn't it?  Because, you can't 
assume that.  And the existing code is arguably kind of wrong.  But 
moreover, this macro also assumes that the "addr" argument has no random 
padding bits.

In the existing code, you can maybe make a local analysis that the code 
is working correctly, although I'm not actually sure.  But if you are 
repackaging this as a general macro under a general-sounding name, then 
the requirements should be more stringent.



pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: Remove shadowed declaration warnings
Next
From: Peter Eisentraut
Date:
Subject: Re: information_schema.view attgenerated