netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Ander Juaristi <a@juaristi.eus>
Cc: netfilter-devel@vger.kernel.org
Subject: Re: [PATCH v2 5/7] nftables: meta: Some small style fixes
Date: Wed, 26 Jun 2019 23:11:33 +0200	[thread overview]
Message-ID: <20190626211133.ijifvft7hv3ygs64@breakpoint.cc> (raw)
In-Reply-To: <20190626204402.5257-5-a@juaristi.eus>

Ander Juaristi <a@juaristi.eus> wrote:
>  - Rename constants: TYPE_TIME_DATE, TYPE_TIME_HOUR, TYPE_TIME_DAY
>  - Use array_size()
>  - Rewrite __hour_type_print_r to get buffer size from a parameter

Thanks!  I think this can be squashed too.

> --- a/src/meta.c
> +++ b/src/meta.c
> @@ -475,7 +475,7 @@ static void day_type_print(const struct expr *expr, struct output_ctx *octx)
>  		"Saturday"
>  	};
>  	uint8_t daynum = mpz_get_uint8(expr->value),
> -		 numdays = sizeof(days) / (3 * 3);
> +		 numdays = array_size(days) - 1;
>  
>  	if (daynum >= 0 && daynum <= numdays)

This '- 1' had me confused, but then you use <= numdays.

Perhaps prefer array_size + "<" operator?

> @@ -505,7 +505,7 @@ static struct error_record *day_type_parse(const struct expr *sym,
>  		"Friday",
>  		"Saturday"
>  	};
> -	int daynum = -1, numdays = (sizeof(days) / 7) - 1;
> +	int daynum = -1, numdays = array_size(days);

... because here the - 1 is missing.

>  		if (cur_tm)
>  			seconds = (seconds + cur_tm->tm_gmtoff) % 86400;
>  
> -		__hour_type_print_r(0, 0, seconds, out);
> +		__hour_type_print_r(0, 0, seconds, out, sizeof(out));

Thanks for doing this.  I know its more code to read but it helps
when someone has to review this later as this got rid of magic
bufsize constants in the snprintf() calls.

>  	.byteorder = BYTEORDER_HOST_ENDIAN,
> -	.size = 8 * BITS_PER_BYTE,
> +	.size = sizeof(uint64_t) * BITS_PER_BYTE,

Thanks.

  reply	other threads:[~2019-06-26 21:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-26 20:43 [PATCH v2 1/7] nftables: meta: Introduce new conditions 'time', 'day' and 'hour' Ander Juaristi
2019-06-26 20:43 ` [PATCH v2 2/7] nftables: meta: hour: Fix integer overflow error Ander Juaristi
2019-06-26 21:07   ` Florian Westphal
2019-06-26 20:43 ` [PATCH v2 3/7] nftables: meta: time: Proper handling of DST Ander Juaristi
2019-06-26 21:07   ` Florian Westphal
2019-06-27 19:10     ` Pablo Neira Ayuso
2019-06-26 20:43 ` [PATCH v2 4/7] nftables: tests/py: Add tests for day and hour Ander Juaristi
2019-06-26 21:06   ` Florian Westphal
2019-06-26 20:44 ` [PATCH v2 5/7] nftables: meta: Some small style fixes Ander Juaristi
2019-06-26 21:11   ` Florian Westphal [this message]
2019-06-26 20:44 ` [PATCH v2 6/7] nftables: Compute result modulo 86400 in case gmtoff is negative Ander Juaristi
2019-06-26 20:44 ` [PATCH v2 7/7] nftables: tests/py: More tests for day and hour Ander Juaristi
2019-06-26 21:12   ` Florian Westphal

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=20190626211133.ijifvft7hv3ygs64@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=a@juaristi.eus \
    --cc=netfilter-devel@vger.kernel.org \
    /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).