DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] examples/cmdline: fix build error with gcc 12
@ 2023-01-18 16:11 Bruce Richardson
  2023-01-18 18:53 ` Ferruh Yigit
  0 siblings, 1 reply; 7+ messages in thread
From: Bruce Richardson @ 2023-01-18 16:11 UTC (permalink / raw)
  To: dev; +Cc: Olivier Matz, Bruce Richardson, stable

When building the example without libbsd and using the DPDK-provided
strlcpy function, a compiler warning is emitted by GCC 12 about the copy
of the parsed string into the resulting object. This is because the
source from cmdline library is 128 bytes and the destination buffer is
64-bytes.

commands.c: In function 'cmd_obj_add_parsed':
.../__BUILDS/build-x86-generic/install/usr/local/include/rte_string_fns.h:61:24: warning: '%s' directive output may be truncated writing up to 127 bytes into a region of size 64 [-Wformat-truncation=]
   61 |         return (size_t)snprintf(dst, size, "%s", src);
      |                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/stdio.h:894,
                 from commands.c:7:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:71:10: note: '__builtin_snprintf' output between 1 and 128 bytes into a destination of size 64

Multiple options are possible to fix this, but the one taken in this
patch is to ensure truncation never occurs by setting the destination
buffer size to be the same as that used by the cmdline library.

Fixes: af75078fece3 ("first public release")
Cc: stable@dpdk.org

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 examples/cmdline/parse_obj_list.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/examples/cmdline/parse_obj_list.h b/examples/cmdline/parse_obj_list.h
index 6516d3e2c2..1223ac1e8b 100644
--- a/examples/cmdline/parse_obj_list.h
+++ b/examples/cmdline/parse_obj_list.h
@@ -12,8 +12,9 @@
 
 #include <sys/queue.h>
 #include <cmdline_parse.h>
+#include <cmdline_parse_string.h>
 
-#define OBJ_NAME_LEN_MAX 64
+#define OBJ_NAME_LEN_MAX sizeof(cmdline_fixed_string_t)
 
 struct object {
 	SLIST_ENTRY(object) next;
-- 
2.34.1


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

end of thread, other threads:[~2023-02-20 11:44 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18 16:11 [PATCH] examples/cmdline: fix build error with gcc 12 Bruce Richardson
2023-01-18 18:53 ` Ferruh Yigit
2023-01-19  8:59   ` Bruce Richardson
2023-01-19 16:44     ` Stephen Hemminger
2023-01-19 18:12       ` Bruce Richardson
2023-02-10 11:26     ` Olivier Matz
2023-02-20 11:44       ` Thomas Monjalon

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).