From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 3/6] tap: Cast TAP_BUF_BYTES - ETH_MAX_MTU to ssize_t, not TAP_BUF_BYTES
Date: Fri, 8 Nov 2024 11:28:43 +1100 [thread overview]
Message-ID: <Zy1bO0OxyyhhMof_@zatzit> (raw)
In-Reply-To: <20241107184331.3164784-4-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1739 bytes --]
On Thu, Nov 07, 2024 at 07:43:28PM +0100, Stefano Brivio wrote:
> Given that we're comparing against 'n', which is signed, we cast
> TAP_BUF_BYTES to ssize_t so that the maximum buffer usage, calculated
> as the difference between TAP_BUF_BYTES and ETH_MAX_MTU, will also be
> signed.
>
> This doesn't necessarily happen on 32-bit architectures, though. On
> armhf and i686, clang-tidy 18.1.8 and 19.1.2 report:
>
> /home/pi/passt/tap.c:1087:16: error: comparison of integers of different signs: 'ssize_t' (aka 'int') and 'unsigned int' [clang-diagnostic-sign-compare,-warnings-as-errors]
> 1087 | for (n = 0; n <= (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n += len) {
> | ~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> cast the whole difference to ssize_t, as we know it's going to be
> positive anyway, instead of relying on that side effect.
>
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> tap.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tap.c b/tap.c
> index f638f2c..a3ba958 100644
> --- a/tap.c
> +++ b/tap.c
> @@ -1084,7 +1084,7 @@ static void tap_pasta_input(struct ctx *c, const struct timespec *now)
>
> tap_flush_pools();
>
> - for (n = 0; n <= (ssize_t)TAP_BUF_BYTES - ETH_MAX_MTU; n += len) {
> + for (n = 0; n <= (ssize_t)(TAP_BUF_BYTES - ETH_MAX_MTU); n += len) {
> len = read(c->fd_tap, pkt_buf + n, ETH_MAX_MTU);
>
> if (len == 0) {
--
David Gibson (he or they) | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
| around.
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2024-11-08 2:23 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-07 18:43 [PATCH 0/6] Fix some more static checker warnings Stefano Brivio
2024-11-07 18:43 ` [PATCH 1/6] dhcpv6: Use for loop instead of goto to avoid false positive cppcheck warning Stefano Brivio
2024-11-08 0:26 ` David Gibson
2024-11-07 18:43 ` [PATCH 2/6] dhcpv6: Turn some option headers pointers to const Stefano Brivio
2024-11-08 0:27 ` David Gibson
2024-11-07 18:43 ` [PATCH 3/6] tap: Cast TAP_BUF_BYTES - ETH_MAX_MTU to ssize_t, not TAP_BUF_BYTES Stefano Brivio
2024-11-08 0:28 ` David Gibson [this message]
2024-11-07 18:43 ` [PATCH 4/6] util: Define small and big thresholds for socket buffers as unsigned long long Stefano Brivio
2024-11-08 0:29 ` David Gibson
2024-11-07 18:43 ` [PATCH 5/6] passt: Use NOLINT clang-tidy block instead of NOLINTNEXTLINE Stefano Brivio
2024-11-08 0:30 ` David Gibson
2024-11-07 18:43 ` [PATCH 6/6] tap, tcp, util: Add some missing SOCK_CLOEXEC flags Stefano Brivio
2024-11-08 0:31 ` David Gibson
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=Zy1bO0OxyyhhMof_@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
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 IMAP folder(s).