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

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

Checks

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

Commit Message

Peng, ZhihongX Oct. 15, 2021, 3:11 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(-)
  

Comments

Peng, ZhihongX Oct. 19, 2021, 6:02 a.m. UTC | #1
> -----Original Message-----
> From: Peng, ZhihongX <zhihongx.peng@intel.com>
> Sent: Friday, October 15, 2021 11:11 PM
> To: david.marchand@redhat.com; Burakov, Anatoly
> <anatoly.burakov@intel.com>; Ananyev, Konstantin
> <konstantin.ananyev@intel.com>; stephen@networkplumber.org;
> Dumitrescu, Cristian <cristian.dumitrescu@intel.com>; Mcnamara, John
> <john.mcnamara@intel.com>
> Cc: dev@dpdk.org; Lin, Xueqin <xueqin.lin@intel.com>; Peng, ZhihongX
> <ZhihongX.Peng@intel.com>; stable@dpdk.org
> Subject: [PATCH v10 4/4] performance-thread: Fix cross compilation failed
> 
> 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(-)
> 
> 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;
> --
> 2.25.1

Hi, John

Can you give me an ack?

Thanks!
  

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;