[Tarantool-patches] [PATCH v2 2/2] bitset: replace zero-length array with flexible-array member

Aleksandr Lyapunov alyapunov at tarantool.org
Mon Nov 30 15:47:48 MSK 2020


Hi!
Thank for the patch!
LGTM now.
I'm glad we found such a laconic solution.

On 11/27/20 3:43 PM, Artem Starshov wrote:
> Zero-lenght arrays are GNU C extension.
> There's ISO C99 flexible array member, which
> is preffered mechanism to declare variable-length types.
>
> Flexible array member allows us to avoid applying sizeof
> operator cause it's incomplete type, so it will be an error
> at compile time. There're any moments else why it's better
> way to implement such structures via FAM:
> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
>
> In this issue it fixed gcc 10 warning:
> "warning: writing 1 byte into
> a region of size 0 [-Wstringop-overflow=]"
>
> Closes #4966
> Closes #5564
> ---
>   src/lib/bitset/bitset.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/bitset/bitset.h b/src/lib/bitset/bitset.h
> index e2ae4f5f6..775de5c07 100644
> --- a/src/lib/bitset/bitset.h
> +++ b/src/lib/bitset/bitset.h
> @@ -69,7 +69,7 @@ struct tt_bitset_page {
>   	size_t first_pos;
>   	rb_node(struct tt_bitset_page) node;
>   	size_t cardinality;
> -	uint8_t data[0];
> +	uint8_t data[];
>   };
>   
>   typedef rb_tree(struct tt_bitset_page) tt_bitset_pages_t;


More information about the Tarantool-patches mailing list