bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix application of sizeof to pointer
@ 2021-10-12 11:16 davidcomponentone
  2021-10-20 17:55 ` Andrii Nakryiko
  0 siblings, 1 reply; 3+ messages in thread
From: davidcomponentone @ 2021-10-12 11:16 UTC (permalink / raw)
  To: ast
  Cc: daniel, davem, kuba, hawk, john.fastabend, andrii, kafai,
	songliubraving, yhs, kpsingh, netdev, bpf, linux-kernel,
	David Yang, Zeal Robot

From: David Yang <davidcomponentone@gmail.com>

The coccinelle check report:
"./samples/bpf/xdp_redirect_cpu_user.c:397:32-38:
ERROR: application of sizeof to pointer"
Using the "strlen" to fix it.

Reported-by: Zeal Robot <zealci@zte.com.cn>
Signed-off-by: David Yang <davidcomponentone@gmail.com>
---
 samples/bpf/xdp_redirect_cpu_user.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
index 6e25fba64c72..d84e6949007c 100644
--- a/samples/bpf/xdp_redirect_cpu_user.c
+++ b/samples/bpf/xdp_redirect_cpu_user.c
@@ -325,7 +325,6 @@ int main(int argc, char **argv)
 	int add_cpu = -1;
 	int ifindex = -1;
 	int *cpu, i, opt;
-	char *ifname;
 	__u32 qsize;
 	int n_cpus;
 
@@ -393,9 +392,8 @@ int main(int argc, char **argv)
 				fprintf(stderr, "-d/--dev name too long\n");
 				goto end_cpu;
 			}
-			ifname = (char *)&ifname_buf;
-			safe_strncpy(ifname, optarg, sizeof(ifname));
-			ifindex = if_nametoindex(ifname);
+			safe_strncpy(ifname_buf, optarg, strlen(ifname_buf));
+			ifindex = if_nametoindex(ifname_buf);
 			if (!ifindex)
 				ifindex = strtoul(optarg, NULL, 0);
 			if (!ifindex) {
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-21  0:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 11:16 [PATCH] Fix application of sizeof to pointer davidcomponentone
2021-10-20 17:55 ` Andrii Nakryiko
2021-10-21  0:50   ` David Yang

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 NNTP newsgroup(s).