netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: [iptables PATCH] nft: Use ARRAY_SIZE() macro in nft_strerror()
Date: Wed, 23 Oct 2019 22:41:49 +0200	[thread overview]
Message-ID: <20191023204149.vushra6ipmjqqd7c@salvia> (raw)
In-Reply-To: <20191023121627.GM26123@orbyte.nwl.cc>

On Wed, Oct 23, 2019 at 02:16:27PM +0200, Phil Sutter wrote:
> 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@nwl.cc>
> > > 
> > > Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
> > 
> > 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

At quick glance I would say that's fine.

  reply	other threads:[~2019-10-23 20:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-18 15:51 [iptables PATCH] nft: Use ARRAY_SIZE() macro in nft_strerror() Phil Sutter
2019-10-23 11:20 ` Pablo Neira Ayuso
2019-10-23 11:23   ` Pablo Neira Ayuso
2019-10-23 12:16     ` Phil Sutter
2019-10-23 20:41       ` Pablo Neira Ayuso [this message]
2019-10-24  8:45         ` Phil Sutter
2019-10-24  9:29           ` Pablo Neira Ayuso
2019-10-24  9:51             ` Phil Sutter
2019-10-24 10:01               ` Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191023204149.vushra6ipmjqqd7c@salvia \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).