From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by passt.top (Postfix, from userid 1000) id 7032A5A0272; Wed, 29 Nov 2023 14:46:10 +0100 (CET) From: Stefano Brivio To: passt-dev@passt.top Subject: [PATCH 1/4] treewide: Use 'z' length modifier for size_t/ssize_t conversions Date: Wed, 29 Nov 2023 14:46:07 +0100 Message-Id: <20231129134610.3796809-2-sbrivio@redhat.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231129134610.3796809-1-sbrivio@redhat.com> References: <20231129134610.3796809-1-sbrivio@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: C7E5K566TY4ESUP2W5GNO7KPZHBRUO4O X-Message-ID-Hash: C7E5K566TY4ESUP2W5GNO7KPZHBRUO4O X-MailFrom: sbrivio@passt.top X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: lemmi@nerd2nerd.org X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Types size_t and ssize_t are not necessarily long, it depends on the architecture. Signed-off-by: Stefano Brivio --- netlink.c | 2 +- packet.c | 14 +++++++------- pcap.c | 4 ++-- tap.c | 12 ++++++------ tcp.c | 3 ++- tcp_splice.c | 8 ++++---- 6 files changed, 22 insertions(+), 21 deletions(-) diff --git a/netlink.c b/netlink.c index 6cc04a0..379d46e 100644 --- a/netlink.c +++ b/netlink.c @@ -130,7 +130,7 @@ static uint32_t nl_send(int s, void *req, uint16_t type, if (n < 0) die("netlink: Failed to send(): %s", strerror(errno)); else if (n < len) - die("netlink: Short send (%lu of %lu bytes)", n, len); + die("netlink: Short send (%zd of %zd bytes)", n, len); return nh->nlmsg_seq; } diff --git a/packet.c b/packet.c index 9589824..12ac76b 100644 --- a/packet.c +++ b/packet.c @@ -36,7 +36,7 @@ void packet_add_do(struct pool *p, size_t len, const char *start, size_t idx = p->count; if (idx >= p->size) { - trace("add packet index %lu to pool with size %lu, %s:%i", + trace("add packet index %zu to pool with size %zu, %s:%i", idx, p->size, func, line); return; } @@ -48,14 +48,14 @@ void packet_add_do(struct pool *p, size_t len, const char *start, } if (start + len > p->buf + p->buf_size) { - trace("add packet start %p, length: %lu, buffer end %p, %s:%i", + trace("add packet start %p, length: %zu, buffer end %p, %s:%i", (void *)start, len, (void *)(p->buf + p->buf_size), func, line); return; } if (len > UINT16_MAX) { - trace("add packet length %lu, %s:%i", len, func, line); + trace("add packet length %zu, %s:%i", len, func, line); return; } @@ -90,7 +90,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, { if (idx >= p->size || idx >= p->count) { if (func) { - trace("packet %lu from pool size: %lu, count: %lu, " + trace("packet %zu from pool size: %zu, count: %zu, " "%s:%i", idx, p->size, p->count, func, line); } return NULL; @@ -98,7 +98,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len > UINT16_MAX || len + offset > UINT32_MAX) { if (func) { - trace("packet data length %lu, offset %lu, %s:%i", + trace("packet data length %zu, offset %zu, %s:%i", len, offset, func, line); } return NULL; @@ -106,7 +106,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (p->pkt[idx].offset + len + offset > p->buf_size) { if (func) { - trace("packet offset plus length %lu from size %lu, " + trace("packet offset plus length %lu from size %zu, " "%s:%i", p->pkt[idx].offset + len + offset, p->buf_size, func, line); } @@ -115,7 +115,7 @@ void *packet_get_do(const struct pool *p, size_t idx, size_t offset, if (len + offset > p->pkt[idx].len) { if (func) { - trace("data length %lu, offset %lu from length %u, " + trace("data length %zu, offset %zu from length %u, " "%s:%i", len, offset, p->pkt[idx].len, func, line); } diff --git a/pcap.c b/pcap.c index 524612a..501d52d 100644 --- a/pcap.c +++ b/pcap.c @@ -101,7 +101,7 @@ void pcap(const char *pkt, size_t len) gettimeofday(&tv, NULL); if (pcap_frame(pkt, len, &tv) != 0) - debug("Cannot log packet, length %lu", len); + debug("Cannot log packet, length %zu", len); } /** @@ -123,7 +123,7 @@ void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offset) for (i = 0; i < n; i++) { if (pcap_frame((char *)iov[i].iov_base + offset, iov[i].iov_len - offset, &tv) != 0) { - debug("Cannot log packet, length %lu", + debug("Cannot log packet, length %zu", iov->iov_len - offset); return; } diff --git a/tap.c b/tap.c index 4f11000..2ceda8d 100644 --- a/tap.c +++ b/tap.c @@ -191,7 +191,7 @@ void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sport, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -214,7 +214,7 @@ void tap_icmp4_send(const struct ctx *c, struct in_addr src, struct in_addr dst, csum_icmp4(icmp4h, icmp4h + 1, len - sizeof(*icmp4h)); if (tap_send(c, buf, len + (data - buf)) < 0) - debug("tap: failed to send %lu bytes (IPv4)", len); + debug("tap: failed to send %zu bytes (IPv4)", len); } /** @@ -278,7 +278,7 @@ void tap_udp6_send(const struct ctx *c, memcpy(data, in, len); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -302,7 +302,7 @@ void tap_icmp6_send(const struct ctx *c, csum_icmp6(icmp6h, src, dst, icmp6h + 1, len - sizeof(*icmp6h)); if (tap_send(c, buf, len + (data - buf)) < 1) - debug("tap: failed to send %lu bytes (IPv6)", len); + debug("tap: failed to send %zu bytes (IPv6)", len); } /** @@ -364,7 +364,7 @@ static void tap_send_remainder(const struct ctx *c, const struct iovec *iov, ssize_t sent = send(c->fd_tap, base + offset, len - offset, MSG_NOSIGNAL); if (sent < 0) { - err("tap: partial frame send (missing %lu bytes): %s", + err("tap: partial frame send (missing %zu bytes): %s", len - offset, strerror(errno)); return; } @@ -433,7 +433,7 @@ size_t tap_send_frames(const struct ctx *c, const struct iovec *iov, size_t n) m = tap_send_frames_pasta(c, iov, n); if (m < n) - debug("tap: failed to send %lu frames of %lu", n - m, n); + debug("tap: failed to send %zu frames of %zu", n - m, n); pcap_multiple(iov, m, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); diff --git a/tcp.c b/tcp.c index 40e3dec..44468ca 100644 --- a/tcp.c +++ b/tcp.c @@ -2570,7 +2570,8 @@ int tcp_tap_handler(struct ctx *c, uint8_t pif, int af, return 1; } - trace("TCP: packet length %lu from tap for index %lu", len, CONN_IDX(conn)); + trace("TCP: packet length %zu from tap for index %lu", + len, CONN_IDX(conn)); if (th->rst) { conn_event(c, conn, CLOSED); diff --git a/tcp_splice.c b/tcp_splice.c index a5c1332..8d08bb4 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -321,7 +321,7 @@ static int tcp_splice_connect_finish(const struct ctx *c, if (fcntl(conn->pipe[side][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set %d->%d pipe size to %lu", + trace("TCP (spliced): cannot set %d->%d pipe size to %zu", side, !side, c->tcp.pipe_size); } } @@ -554,7 +554,7 @@ retry: readlen = splice(conn->s[fromside], NULL, conn->pipe[fromside][1], NULL, c->tcp.pipe_size, SPLICE_F_MOVE | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from read-side call", readlen); + trace("TCP (spliced): %zi from read-side call", readlen); if (readlen < 0) { if (errno == EINTR) goto retry; @@ -580,7 +580,7 @@ eintr: written = splice(conn->pipe[fromside][0], NULL, conn->s[!fromside], NULL, to_write, SPLICE_F_MOVE | more | SPLICE_F_NONBLOCK); - trace("TCP (spliced): %li from write-side call (passed %lu)", + trace("TCP (spliced): %zi from write-side call (passed %zu)", written, to_write); /* Most common case: skip updating counters. */ @@ -718,7 +718,7 @@ static void tcp_splice_pipe_refill(const struct ctx *c) if (fcntl(splice_pipe_pool[i][0], F_SETPIPE_SZ, c->tcp.pipe_size)) { - trace("TCP (spliced): cannot set pool pipe size to %lu", + trace("TCP (spliced): cannot set pool pipe size to %zu", c->tcp.pipe_size); } } -- 2.39.2