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

Message ID 20211015142739.1876210-4-zhihongx.peng@intel.com (mailing list archive)
State Superseded, archived
Headers
Series [v10,1/4] Enable ASan for memory detector on DPDK |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Peng, ZhihongX Oct. 15, 2021, 2:27 p.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>
---
 examples/performance-thread/common/lthread.c       | 2 +-
 examples/performance-thread/common/lthread_cond.c  | 4 ++--
 examples/performance-thread/common/lthread_mutex.c | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)
  

Patch

diff --git a/examples/performance-thread/common/lthread.c b/examples/performance-thread/common/lthread.c
index 3f1f48db43..dd4b3b27ee 100644
--- a/examples/performance-thread/common/lthread.c
+++ b/examples/performance-thread/common/lthread.c
@@ -463,6 +463,6 @@  void lthread_set_funcname(const char *f)
 {
 	struct lthread *lt = THIS_LTHREAD;
 
-	strncpy(lt->funcname, f, sizeof(lt->funcname));
+	strncpy(lt->funcname, f, sizeof(lt->funcname) - 1);
 	lt->funcname[sizeof(lt->funcname)-1] = 0;
 }
diff --git a/examples/performance-thread/common/lthread_cond.c b/examples/performance-thread/common/lthread_cond.c
index cdcc7a7b5a..6ec8bc7e82 100644
--- a/examples/performance-thread/common/lthread_cond.c
+++ b/examples/performance-thread/common/lthread_cond.c
@@ -57,9 +57,9 @@  lthread_cond_init(char *name, struct lthread_cond **cond,
 	}
 
 	if (name == NULL)
-		strncpy(c->name, "no name", sizeof(c->name));
+		strncpy(c->name, "no name", sizeof(c->name) - 1);
 	else
-		strncpy(c->name, name, sizeof(c->name));
+		strncpy(c->name, name, sizeof(c->name) - 1);
 	c->name[sizeof(c->name)-1] = 0;
 
 	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..7e5da609b1 100644
--- a/examples/performance-thread/common/lthread_mutex.c
+++ b/examples/performance-thread/common/lthread_mutex.c
@@ -52,9 +52,9 @@  lthread_mutex_init(char *name, struct lthread_mutex **mutex,
 	}
 
 	if (name == NULL)
-		strncpy(m->name, "no name", sizeof(m->name));
+		strncpy(m->name, "no name", sizeof(m->name) - 1);
 	else
-		strncpy(m->name, name, sizeof(m->name));
+		strncpy(m->name, name, sizeof(m->name) - 1);
 	m->name[sizeof(m->name)-1] = 0;
 
 	m->root_sched = THIS_SCHED;