On 19.10.26 15:47, David Geier wrote:
Hi Peter!
Ideally, we'd want to use the maximum level -fstrict-flex-arrays=3,
which would only allow flexible array members declared with the C
standard "[]". But we do need to permit flexible array members declared
with "[1]" in a few cases because standard C does not allow flexible
array members as the only element in a struct. Affected are:
- struct RevmapContents
- struct ReplicationSlotCtlData
- union pgresult_data
(Some of these have comments "It should be declared
[FLEXIBLE_ARRAY_MEMBER], but for some reason you can't do that in an
otherwise-empty struct.")
I think that's because sizeof any struct in C must be > 0. If a struct
contains no other member than an [] array, sizeof would be 0.
Yes, that's probably why.
Can we maybe use typedefs instead of structs for the cases you
mentioned? At least it's valid C to write typedef char Foo[].
Yeah, maybe some of this code could be rewritten to avoid this, but it
doesn't seem very urgent.
There is also:
- struct sqlda_struct
which, as I understand it, is bound by external API specification, so
not easy to change.
If we turned on -fstrict-flex-arrays=3, these would become undefined
behavior and trigger the ubsan sanitizer.
The compiler setting can be changed on a per-struct basis via
__attribute__((strict_flex_arrays(N)));
This only works with gcc, not clang, so it's not a viable solution.