aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2024-11-07 18:58:49 +0100
committerStefano Brivio <sbrivio@redhat.com>2024-11-08 08:24:45 +0100
commit87940f9aa72a342988e89b9509c2572e494d91a6 (patch)
treec496095e09d2660a35457245cbf232ee4120fee1
parent1feb90fe627959e4903e01ba83249fa33c4d472d (diff)
downloadpasst-87940f9aa72a342988e89b9509c2572e494d91a6.tar
passt-87940f9aa72a342988e89b9509c2572e494d91a6.tar.gz
passt-87940f9aa72a342988e89b9509c2572e494d91a6.tar.bz2
passt-87940f9aa72a342988e89b9509c2572e494d91a6.tar.lz
passt-87940f9aa72a342988e89b9509c2572e494d91a6.tar.xz
passt-87940f9aa72a342988e89b9509c2572e494d91a6.tar.zst
passt-87940f9aa72a342988e89b9509c2572e494d91a6.zip
tap: Cast TAP_BUF_BYTES - ETH_MAX_MTU to ssize_t, not TAP_BUF_BYTES
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>
-rw-r--r--tap.c2
1 files changed, 1 insertions, 1 deletions
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) {