[dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include
Stephen Hemminger
stephen at networkplumber.org
Wed Apr 3 17:51:32 CEST 2019
On Wed, 3 Apr 2019 15:45:04 +0100
Bruce Richardson <bruce.richardson at intel.com> wrote:
> diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c
> index d215acecc..a542f6f5d 100644
> --- a/lib/librte_ring/rte_ring.c
> +++ b/lib/librte_ring/rte_ring.c
> @@ -78,7 +78,7 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
>
> /* init the ring structure */
> memset(r, 0, sizeof(*r));
> - ret = snprintf(r->name, sizeof(r->name), "%s", name);
> + ret = strlcpy(r->name, name, sizeof(r->name));
> if (ret < 0 || ret >= (int)sizeof(r->name))
I would rather use the name length that is part of the header file.
if (strnlen(name, RTE_RING_NAMESIZE) == RTE_RING_NAMESIZE)
return -ENAMETOOLONG;
strlcpy(r->name, name, sizeof(r->name))
More information about the dev
mailing list