Skip to content

Commit

Permalink
examples/performance-thread: fix build with ASan
Browse files Browse the repository at this point in the history
[ upstream commit 4d2d125 ]

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>
  • Loading branch information
Zhihong Peng authored and cpaelzer committed Nov 30, 2021
1 parent 7c712c5 commit 478db9f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/performance-thread/common/lthread.c
Expand Up @@ -20,6 +20,7 @@
#include <sys/mman.h>

#include <rte_log.h>
#include <rte_string_fns.h>
#include <ctx.h>
#include <stack.h>

Expand Down Expand Up @@ -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;
strlcpy(lt->funcname, f, sizeof(lt->funcname));
}
6 changes: 3 additions & 3 deletions examples/performance-thread/common/lthread_cond.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions examples/performance-thread/common/lthread_mutex.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 478db9f

Please sign in to comment.