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 Reviewed-by: David Gibson > --- > 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