From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by dpdk.org (Postfix) with ESMTP id 87DCB1B44E for ; Thu, 4 Apr 2019 20:05:09 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 282F621C0F; Thu, 4 Apr 2019 14:05:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 04 Apr 2019 14:05:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=mesmtp; bh=RwxnJiBNBWrcT+4guU8pNI/FEnglJrruJpc65olSv/Q=; b=F40lz9voLAnv pO2taDfHQzw9zqaYlwP4R5NW4fsXJSqcKCGIBUPXPdGoD46n2JtSonc8pDvKSrIP 5rq/2R9Y/SKbCxZu76gSySnNpbjUabQ4mVczfU5QuhBk1xzHog/B18TJpJnb6/n4 dNsLK2E35jjvEAGZgXg3uomVrYVSJFQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=RwxnJiBNBWrcT+4guU8pNI/FEnglJrruJpc65olSv /Q=; b=0zjnAcqjtshqDDNKpBiMVI2H/deDFxLlzta7wpeUI6JME7rmMDjUPKJrz 3dE7auhwkAD5NfS3YzRpH+Kisu2FzydU7W2zJCP7hKdIuxc+tFx19d7fbUy22+Uk KYZ6kS2hVj0G3vgHrGaU3p3YPz0tSxA1qYOt8+gKQj1otF5QbKyU15ff6C3nWdWa XcyMUvSkXEpBwAwQ0C7aG2HzSNq8Gz84RfjLLf9tfQX/ZgwtP04A3iBHIWK1ILeb 5dkMrWn1MSv5bkeXSdoiJOt4jlUVAel3ENqls24uPGzYq7oMAwtdZq0BGqnUZtlK dYbQU7cxAwzNE0zEDLefOglocDxhg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrtdehgdduudelucdltddurdeguddtrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttddv necuhfhrohhmpefvhhhomhgrshcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjh grlhhonhdrnhgvtheqnecukfhppeejjedrudefgedrvddtfedrudekgeenucfrrghrrghm pehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvthenucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 7CAE310397; Thu, 4 Apr 2019 14:05:07 -0400 (EDT) From: Thomas Monjalon To: Bruce Richardson Cc: dev@dpdk.org, Stephen Hemminger Date: Thu, 04 Apr 2019 20:05:06 +0200 Message-ID: <4698261.tayNczNUhG@xps> In-Reply-To: <20190403155638.GA1336@bricha3-MOBL.ger.corp.intel.com> References: <20190403144505.46234-1-bruce.richardson@intel.com> <20190403085132.1fa33194@shemminger-XPS-13-9360> <20190403155638.GA1336@bricha3-MOBL.ger.corp.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Subject: Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 04 Apr 2019 18:05:09 -0000 03/04/2019 17:56, Bruce Richardson: > On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote: > > On Wed, 3 Apr 2019 15:45:04 +0100 > > Bruce Richardson 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)) > > > Yes, though honestly it's a matter of preference. Since this was a scripted > replacement each change wasn't checked in too much detail other than a > cursory check for correctness. I prefer using sizeof/strlen rather than the constant used for allocation. Reasons are: - it's easier to understand the intent - it's easier to change how the allocation size is chosen From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by dpdk.space (Postfix) with ESMTP id 72ABEA0679 for ; Thu, 4 Apr 2019 20:05:12 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E4BA91B450; Thu, 4 Apr 2019 20:05:10 +0200 (CEST) Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) by dpdk.org (Postfix) with ESMTP id 87DCB1B44E for ; Thu, 4 Apr 2019 20:05:09 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 282F621C0F; Thu, 4 Apr 2019 14:05:09 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Thu, 04 Apr 2019 14:05:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s=mesmtp; bh=RwxnJiBNBWrcT+4guU8pNI/FEnglJrruJpc65olSv/Q=; b=F40lz9voLAnv pO2taDfHQzw9zqaYlwP4R5NW4fsXJSqcKCGIBUPXPdGoD46n2JtSonc8pDvKSrIP 5rq/2R9Y/SKbCxZu76gSySnNpbjUabQ4mVczfU5QuhBk1xzHog/B18TJpJnb6/n4 dNsLK2E35jjvEAGZgXg3uomVrYVSJFQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=RwxnJiBNBWrcT+4guU8pNI/FEnglJrruJpc65olSv /Q=; b=0zjnAcqjtshqDDNKpBiMVI2H/deDFxLlzta7wpeUI6JME7rmMDjUPKJrz 3dE7auhwkAD5NfS3YzRpH+Kisu2FzydU7W2zJCP7hKdIuxc+tFx19d7fbUy22+Uk KYZ6kS2hVj0G3vgHrGaU3p3YPz0tSxA1qYOt8+gKQj1otF5QbKyU15ff6C3nWdWa XcyMUvSkXEpBwAwQ0C7aG2HzSNq8Gz84RfjLLf9tfQX/ZgwtP04A3iBHIWK1ILeb 5dkMrWn1MSv5bkeXSdoiJOt4jlUVAel3ENqls24uPGzYq7oMAwtdZq0BGqnUZtlK dYbQU7cxAwzNE0zEDLefOglocDxhg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrtdehgdduudelucdltddurdeguddtrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpih gvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttddv necuhfhrohhmpefvhhhomhgrshcuofhonhhjrghlohhnuceothhhohhmrghssehmohhnjh grlhhonhdrnhgvtheqnecukfhppeejjedrudefgedrvddtfedrudekgeenucfrrghrrghm pehmrghilhhfrhhomhepthhhohhmrghssehmohhnjhgrlhhonhdrnhgvthenucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from xps.localnet (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 7CAE310397; Thu, 4 Apr 2019 14:05:07 -0400 (EDT) From: Thomas Monjalon To: Bruce Richardson Cc: dev@dpdk.org, Stephen Hemminger Date: Thu, 04 Apr 2019 20:05:06 +0200 Message-ID: <4698261.tayNczNUhG@xps> In-Reply-To: <20190403155638.GA1336@bricha3-MOBL.ger.corp.intel.com> References: <20190403144505.46234-1-bruce.richardson@intel.com> <20190403085132.1fa33194@shemminger-XPS-13-9360> <20190403155638.GA1336@bricha3-MOBL.ger.corp.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" Subject: Re: [dpdk-dev] [PATCH 4/5] replace snprintf with strlcpy without adding extra include X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Message-ID: <20190404180506.8w5gbIouYAyfZO17LsreDGLqBZt8FiBhhlhEHAQclvw@z> 03/04/2019 17:56, Bruce Richardson: > On Wed, Apr 03, 2019 at 08:51:32AM -0700, Stephen Hemminger wrote: > > On Wed, 3 Apr 2019 15:45:04 +0100 > > Bruce Richardson 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)) > > > Yes, though honestly it's a matter of preference. Since this was a scripted > replacement each change wasn't checked in too much detail other than a > cursory check for correctness. I prefer using sizeof/strlen rather than the constant used for allocation. Reasons are: - it's easier to understand the intent - it's easier to change how the allocation size is chosen