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.

Can we maybe use typedefs instead of structs for the cases you
mentioned? At least it's valid C to write typedef char Foo[].

> 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)));

--
David Geier


Reply via email to