Re: [iptables PATCH] nft: Use ARRAY_SIZE() macro in nft_strerror()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Pablo,

On Wed, Oct 23, 2019 at 01:23:11PM +0200, Pablo Neira Ayuso wrote:
> On Wed, Oct 23, 2019 at 01:20:24PM +0200, Pablo Neira Ayuso wrote:
> > On Fri, Oct 18, 2019 at 05:51:14PM +0200, Phil Sutter wrote:
> > > Variable 'table' is an array of type struct table_struct, so this is a
> > > classical use-case for ARRAY_SIZE() macro.
> > > 
> > > Signed-off-by: Phil Sutter <phil@xxxxxx>
> > 
> > Acked-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
> 
> BTW, probably good to add the array check?
> 
> https://sourceforge.net/p/libhx/libhx/ci/master/tree/include/libHX/defs.h#l152

Copying from kernel sources, do you think that's fine?

|  #      ifndef ARRAY_SIZE
| -#              define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x)))
| +#              define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:(-!!(e)); }))
| +#              define __same_type(a, b) \
| +                       __builtin_types_compatible_p(typeof(a), typeof(b))
| +/*             &a[0] degrades to a pointer: a different type from an array */
| +#              define __must_be_array(a) \
| +                       BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
| +#              define ARRAY_SIZE(x) (sizeof(x) / sizeof(*(x))) + __must_be_array(x)
|  #      endif

Cheers, Phil



[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux