From: Yang Xiuwei <yangxiuwei@kylinos.cn>
To: axboe@kernel.dk
Cc: io-uring@vger.kernel.org, Yang Xiuwei <yangxiuwei@kylinos.cn>
Subject: [PATCH 1/2] examples/send-zerocopy: fix -Wstringop-truncation on ifr.ifr_name
Date: Sat, 14 Mar 2026 16:35:37 +0800 [thread overview]
Message-ID: <20260314083538.791693-2-yangxiuwei@kylinos.cn> (raw)
In-Reply-To: <20260314083538.791693-1-yangxiuwei@kylinos.cn>
strncpy(ifr.ifr_name, cfg_ifname, sizeof(ifr.ifr_name)) triggers
-Wstringop-truncation because the bound equals the destination size,
so the compiler assumes the result may not be null-terminated. Use
sizeof(ifr.ifr_name) - 1 as the bound so at most 15 bytes are copied.
Fixes: 3e4f05342662 ("examples/send-zerocopy: use strncpy() to copy interface name")
Signed-off-by: Yang Xiuwei <yangxiuwei@kylinos.cn>
---
examples/send-zerocopy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/examples/send-zerocopy.c b/examples/send-zerocopy.c
index f0248d20..b2821af6 100644
--- a/examples/send-zerocopy.c
+++ b/examples/send-zerocopy.c
@@ -353,7 +353,7 @@ static void do_tx(struct thread_data *td, int domain, int type, int protocol)
struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, cfg_ifname, sizeof(ifr.ifr_name));
+ strncpy(ifr.ifr_name, cfg_ifname, sizeof(ifr.ifr_name) - 1);
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) < 0)
t_error(1, errno, "Binding to device failed\n");
--
2.25.1
next prev parent reply other threads:[~2026-03-14 8:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 8:35 [PATCH Liburing 0/2] build and compiler warning fixes Yang Xiuwei
2026-03-14 8:35 ` Yang Xiuwei [this message]
2026-03-14 8:35 ` [PATCH 2/2] test/cbpf_filter: skip when openat2.h is not available Yang Xiuwei
2026-03-14 13:35 ` Jens Axboe
2026-03-15 5:02 ` Yang Xiuwei
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=20260314083538.791693-2-yangxiuwei@kylinos.cn \
--to=yangxiuwei@kylinos.cn \
--cc=axboe@kernel.dk \
--cc=io-uring@vger.kernel.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox