When compiling in debug mode, the format-truncation check
raises a warning:

In function 'secondary_msl_create_walk':
     lib/eal/linux/eal_memalloc.c:1401:50:
     error: '%i' directive output may be truncated writing
     between 1 and 11 bytes into a region of size between 0 and 63
     [-Werror=format-truncation=]
     note: 'snprintf' output between 3 and 76 bytes
     into a destination of size 64
 1401 |         snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
 1402 |                 primary_msl->memseg_arr.name, getpid());

This is a new warning enabled in DPDK 26.03.
It is solved by checking the return of snprintf.

Bugzilla ID: 1878

Signed-off-by: Thomas Monjalon <[email protected]>
---
 lib/eal/linux/eal_memalloc.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/eal/linux/eal_memalloc.c b/lib/eal/linux/eal_memalloc.c
index d9e8ea76b9..4dee224ac5 100644
--- a/lib/eal/linux/eal_memalloc.c
+++ b/lib/eal/linux/eal_memalloc.c
@@ -1398,8 +1398,13 @@ secondary_msl_create_walk(const struct rte_memseg_list 
*msl,
        local_msl = &local_memsegs[msl_idx];
 
        /* create distinct fbarrays for each secondary */
-       snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
+       ret = snprintf(name, RTE_FBARRAY_NAME_LEN, "%s_%i",
                primary_msl->memseg_arr.name, getpid());
+       if (ret >= RTE_FBARRAY_NAME_LEN) {
+               EAL_LOG(ERR, "fbarray name %s_%i is too long",
+                               primary_msl->memseg_arr.name, getpid());
+               return -1;
+       }
 
        ret = rte_fbarray_init(&local_msl->memseg_arr, name,
                primary_msl->memseg_arr.len,
-- 
2.52.0

Reply via email to