]> git.droids-corp.org - dpdk.git/commitdiff
examples/performance-thread: fix build with ASan
authorZhihong Peng <zhihongx.peng@intel.com>
Wed, 20 Oct 2021 07:46:43 +0000 (15:46 +0800)
committerDavid Marchand <david.marchand@redhat.com>
Fri, 29 Oct 2021 13:25:34 +0000 (15:25 +0200)
Code changes to avoid the following build error:
"strncpy specified bound XX equals destination size".

Signed-off-by: Xueqin Lin <xueqin.lin@intel.com>
Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
examples/performance-thread/common/lthread.c
examples/performance-thread/common/lthread_cond.c
examples/performance-thread/common/lthread_mutex.c

index 98123f34f8401b04b756e89345b6a56048027e21..009374a8c3e077dd18931918ab4d78190dcb768d 100644 (file)
@@ -20,6 +20,7 @@
 #include <sys/mman.h>
 
 #include <rte_log.h>
+#include <rte_string_fns.h>
 #include <ctx.h>
 #include <stack.h>
 
@@ -465,6 +466,5 @@ void lthread_set_funcname(const char *f)
 {
        struct lthread *lt = THIS_LTHREAD;
 
-       strncpy(lt->funcname, f, sizeof(lt->funcname));
-       lt->funcname[sizeof(lt->funcname)-1] = 0;
+       strlcpy(lt->funcname, f, sizeof(lt->funcname));
 }
index cdcc7a7b5a24848d70058a42bbf5a3a1fb02b7f8..e7be17089aad620a6d763551557c16737a1db04e 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <rte_log.h>
 #include <rte_common.h>
+#include <rte_string_fns.h>
 
 #include "lthread_api.h"
 #include "lthread_diag_api.h"
@@ -57,10 +58,9 @@ lthread_cond_init(char *name, struct lthread_cond **cond,
        }
 
        if (name == NULL)
-               strncpy(c->name, "no name", sizeof(c->name));
+               strlcpy(c->name, "no name", sizeof(c->name));
        else
-               strncpy(c->name, name, sizeof(c->name));
-       c->name[sizeof(c->name)-1] = 0;
+               strlcpy(c->name, name, sizeof(c->name));
 
        c->root_sched = THIS_SCHED;
 
index 061fc5c19a6baa1a02d7d65a39ab1c3a6c3ddf61..f3ec7c1c60cd1ef971a5a6b6fcc5b769fb3091d8 100644 (file)
@@ -19,6 +19,7 @@
 #include <rte_log.h>
 #include <rte_spinlock.h>
 #include <rte_common.h>
+#include <rte_string_fns.h>
 
 #include "lthread_api.h"
 #include "lthread_int.h"
@@ -52,10 +53,9 @@ lthread_mutex_init(char *name, struct lthread_mutex **mutex,
        }
 
        if (name == NULL)
-               strncpy(m->name, "no name", sizeof(m->name));
+               strlcpy(m->name, "no name", sizeof(m->name));
        else
-               strncpy(m->name, name, sizeof(m->name));
-       m->name[sizeof(m->name)-1] = 0;
+               strlcpy(m->name, name, sizeof(m->name));
 
        m->root_sched = THIS_SCHED;
        m->owner = NULL;