From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, lemmi@nerd2nerd.org
Subject: Re: [PATCH v2 1/3] treewide: Use 'z' length modifier for size_t/ssize_t conversions
Date: Fri, 1 Dec 2023 11:01:59 +1100 [thread overview]
Message-ID: <ZWkid8vxgMFR6PJq@zatzit> (raw)
In-Reply-To: <20231130100726.4151850-2-sbrivio@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 8631 bytes --]
On Thu, Nov 30, 2023 at 11:07:24AM +0100, Stefano Brivio wrote:
> Types size_t and ssize_t are not necessarily long, it depends on the
> architecture.
>
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> 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..0a23584 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 %zi)",
> 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);
> }
> }
--
David Gibson | 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:[~2023-12-01 0:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-30 10:07 [PATCH v2 0/3] Fix some build warnings and errors for 32-bit and musl Stefano Brivio
2023-11-30 10:07 ` [PATCH v2 1/3] treewide: Use 'z' length modifier for size_t/ssize_t conversions Stefano Brivio
2023-12-01 0:01 ` David Gibson [this message]
2023-11-30 10:07 ` [PATCH v2 2/3] packet: Offset plus length is not always uint32_t, but it's always size_t Stefano Brivio
2023-12-01 0:02 ` David Gibson
2023-11-30 10:07 ` [PATCH v2 3/3] port_fwd, util: Include additional headers to fix build with musl Stefano Brivio
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=ZWkid8vxgMFR6PJq@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=lemmi@nerd2nerd.org \
--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).