[v11,4/4] performance-thread: Fix cross compilation failed

Message ID 20211019101207.1451058-4-zhihongx.peng@intel.com (mailing list archive)
State Superseded, archived
Delegated to: David Marchand
Headers
Series [v11,1/4] Enable ASan for memory detector on DPDK |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-spell-check-testing warning Testing issues
ci/github-robot: build success github build: passed
ci/iol-broadcom-Functional success Functional Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing fail Testing issues
ci/iol-x86_64-compile-testing success Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS

Commit Message

Peng, ZhihongX Oct. 19, 2021, 10:12 a.m. UTC
  From: Zhihong Peng <zhihongx.peng@intel.com>

The gcc(arm-linux-gcc) will check code more stricter when ASan enabled.
"strncpy specified bound XX equals destination size" error occurs here.

Fixes: 116819b9ed0d ("examples/performance-thread: add lthread subsystem")
Cc: stable@dpdk.org

Signed-off-by: Xueqin Lin <xueqin.lin@intel.com>
Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
---
v11: Use rte_strlcpy to replace strncpy.
---
 examples/performance-thread/common/lthread.c       | 4 ++--
 examples/performance-thread/common/lthread_cond.c  | 6 +++---
 examples/performance-thread/common/lthread_mutex.c | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)
  

Comments

Bruce Richardson Oct. 19, 2021, 10:37 a.m. UTC | #1
On Tue, Oct 19, 2021 at 06:12:07PM +0800, zhihongx.peng@intel.com wrote:
> From: Zhihong Peng <zhihongx.peng@intel.com>
> 
> The gcc(arm-linux-gcc) will check code more stricter when ASan enabled.
> "strncpy specified bound XX equals destination size" error occurs here.
> 
> Fixes: 116819b9ed0d ("examples/performance-thread: add lthread subsystem")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Xueqin Lin <xueqin.lin@intel.com>
> Signed-off-by: Zhihong Peng <zhihongx.peng@intel.com>
> ---
> v11: Use rte_strlcpy to replace strncpy.
> ---

+1 to using strlcpy, but it should be "strlcpy" rather than "rte_strlcpy"
which should be used. Analysis tools are likely to be familiar with strlcpy
but won't know the DPDK-specific version of it.

With that change to remove the rte_ prefix

Acked-by: Bruce Richardson <bruce.richardson@intel.com>

/Bruce
  

Patch

diff --git a/examples/performance-thread/common/lthread.c b/examples/performance-thread/common/lthread.c
index 3f1f48db43..7949beb8e2 100644
--- a/examples/performance-thread/common/lthread.c
+++ b/examples/performance-thread/common/lthread.c
@@ -20,6 +20,7 @@ 
 #include <sys/mman.h>
 
 #include <rte_log.h>
+#include <rte_string_fns.h>
 #include <ctx.h>
 #include <stack.h>
 
@@ -463,6 +464,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;
+	rte_strlcpy(lt->funcname, f, sizeof(lt->funcname));
 }
diff --git a/examples/performance-thread/common/lthread_cond.c b/examples/performance-thread/common/lthread_cond.c
index cdcc7a7b5a..398735c192 100644
--- a/examples/performance-thread/common/lthread_cond.c
+++ b/examples/performance-thread/common/lthread_cond.c
@@ -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));
+		rte_strlcpy(c->name, "no name", sizeof(c->name));
 	else
-		strncpy(c->name, name, sizeof(c->name));
-	c->name[sizeof(c->name)-1] = 0;
+		rte_strlcpy(c->name, name, sizeof(c->name));
 
 	c->root_sched = THIS_SCHED;
 
diff --git a/examples/performance-thread/common/lthread_mutex.c b/examples/performance-thread/common/lthread_mutex.c
index 01da6cad4f..1911e5ac67 100644
--- a/examples/performance-thread/common/lthread_mutex.c
+++ b/examples/performance-thread/common/lthread_mutex.c
@@ -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));
+		rte_strlcpy(m->name, "no name", sizeof(m->name));
 	else
-		strncpy(m->name, name, sizeof(m->name));
-	m->name[sizeof(m->name)-1] = 0;
+		rte_strlcpy(m->name, name, sizeof(m->name));
 
 	m->root_sched = THIS_SCHED;
 	m->owner = NULL;