On 10/02/2024 02.16, Kees Cook wrote:
> With the coming support for the __counted_by struct member attribute, we
> will need a way to add such annotations to the places where
> DECLARE_FLEX_ARRAY() is used. Introduce DECLARE_FLEX_ARRAY_ATTR() which
> takes a third argument: the attributes to apply to the flexible array.
> 

> - * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
> - *
> + * __DECLARE_FLEX_ARRAY_ATTR() - Declare a flexible array usable in a union
>   * @TYPE: The type of each flexible array element
>   * @NAME: The name of the flexible array member
> + * @ATTRS: The list of member attributes to apply
>   *
>   * In order to have a flexible array member in a union or alone in a
>   * struct, it needs to be wrapped in an anonymous struct with at least 1
>   * named member, but that member can be empty.
>   */
> -#define __DECLARE_FLEX_ARRAY(TYPE, NAME)     \
> +#define __DECLARE_FLEX_ARRAY_ATTR(TYPE, NAME, ATTRS) \
>       struct { \
>               struct { } __empty_ ## NAME; \
> -             TYPE NAME[]; \
> +             TYPE NAME[] ATTRS; \
>       }

Is it too ugly to not introduce a separate _ATTR macro but instead just do

#define __DECLARE_FLEX_ARRAY(TYPE, NAME, ...) \
  ...
  TYPE NAME[] __VA_ARGS__;

?

Rasmus


Reply via email to