On Mon, Oct 12, 2026 at 08:59:19PM +0000, Bill Wendling wrote:
> The two parts of the '__builtin_choose_expr()' had different arithmetic
> expressions. This patch correct it so that both parts calculate:
>
> COUNT * sizeof(*MEMBER) + __must_be_array(MEMBER)
>
> In practice, the call to '__must_be_array' is meant to assert if
> 'MEMBER' isn't an array and return '0' otherwise. However, symmetry is
> less prone to subtle errors (and far more satisfying).
>
> Fixes: 230f6fa2c1db ("overflow: Provide constant expression struct_size")
A Fixes trailer implies a bug being solved. What problem is there here?
I only see downsides to this change: this adds even more layers of
macros and inlinings to gain the size_add() for a constant integer 0.
?
> - size_mul(count, sizeof(*(p)->member) +
> __must_be_array((p)->member)))
> + size_add(size_mul(count, sizeof(*(p)->member)), \
> + __must_be_array((p)->member)))
--
Kees Cook