From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124])
	by inbox.dpdk.org (Postfix) with ESMTP id EB11D428CE;
	Tue,  4 Apr 2023 17:54:32 +0200 (CEST)
Received: from mails.dpdk.org (localhost [127.0.0.1])
	by mails.dpdk.org (Postfix) with ESMTP id C8BC040EF0;
	Tue,  4 Apr 2023 17:54:32 +0200 (CEST)
Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182])
 by mails.dpdk.org (Postfix) with ESMTP id 7E2F440A7E
 for <dev@dpdk.org>; Tue,  4 Apr 2023 17:54:31 +0200 (CEST)
Received: by linux.microsoft.com (Postfix, from userid 1086)
 id C3F09210DD9D; Tue,  4 Apr 2023 08:54:30 -0700 (PDT)
DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C3F09210DD9D
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;
 s=default; t=1680623670;
 bh=mGA7So62oxgAunhjETmYjXTFoqTShH8aMPiCqVeQaKE=;
 h=Date:From:To:Cc:Subject:References:In-Reply-To:From;
 b=L+AjZFwCW//zya6pCYe4brmBZBayZ/ujbmPlwYtomfTP2U2JA95cKm3Gl5IOZxxBD
 0uRqs90xsqUtmlHSvwa7xNTt87x5xMiaBgCBw0ucPfftOyasKkbvnZeKUR+f8b1Eza
 7nOBgQ+HBFeyXs/LxmwA5ispcQ4xNJsELREe0V6k=
Date: Tue, 4 Apr 2023 08:54:30 -0700
From: Tyler Retzlaff <roretzla@linux.microsoft.com>
To: Bruce Richardson <bruce.richardson@intel.com>
Cc: dev@dpdk.org, ciara.power@intel.com, david.marchand@redhat.com,
 thomas@monjalon.net
Subject: Re: [PATCH v3] telemetry: use portable syntax to initialize array
Message-ID: <20230404155430.GD23247@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net>
References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com>
 <1680548365-16525-1-git-send-email-roretzla@linux.microsoft.com>
 <1680548365-16525-2-git-send-email-roretzla@linux.microsoft.com>
 <ZCvk+KDIeRM+BZ8m@bricha3-MOBL.ger.corp.intel.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <ZCvk+KDIeRM+BZ8m@bricha3-MOBL.ger.corp.intel.com>
User-Agent: Mutt/1.5.21 (2010-09-15)
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org

On Tue, Apr 04, 2023 at 09:51:04AM +0100, Bruce Richardson wrote:
> On Mon, Apr 03, 2023 at 11:59:25AM -0700, Tyler Retzlaff wrote:
> > Use of ranges in designated initialization are a non-standard gcc
> > extension. Use loops to initialize permitted characters on first use.
> > 
> > Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>
> 
> > ---
> >  lib/telemetry/telemetry_data.c | 22 +++++++++++++++-------
> >  1 file changed, 15 insertions(+), 7 deletions(-)
> > 
> > diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
> > index 2bac2de..562b387 100644
> > --- a/lib/telemetry/telemetry_data.c
> > +++ b/lib/telemetry/telemetry_data.c
> > @@ -152,13 +152,21 @@
> >  static bool
> >  valid_name(const char *name)
> >  {
> > -	char allowed[128] = {
> > -			['0' ... '9'] = 1,
> > -			['A' ... 'Z'] = 1,
> > -			['a' ... 'z'] = 1,
> > -			['_'] = 1,
> > -			['/'] = 1,
> > -	};
> > +	int index;
> 
> My preference would be to limit the scope of index to the if block, but ok
> to keep as here.

yes, mine too.  but i forgot we aren't C99 (yet) so i had to move it for
this patch.

> 
> [In fact, when we switch to C11, I'd love to see the coding standards
> relaxed to allow loop variable definition inside the for statement itself]

i'm for it, in fact for any variable i prefer declaration at or near
first use because it let's me const more. but i know that can be an
unpopular opinion so no need to hit 'r' to tell me off, i will follow
any and all documented convention the community has.

> 
> > +	static bool initialized;
> > +	static char allowed[128];
> > +
> > +	if (!initialized) {
> > +		for (index = '0'; index <= '9'; index++)
> > +			allowed[index] = 1;
> > +		for (index = 'A'; index <= 'Z'; index++)
> > +			allowed[index] = 1;
> > +		for (index = 'a'; index <= 'z'; index++)
> > +			allowed[index] = 1;
> > +		allowed[(int)'_'] = allowed[(int)'/'] = 1;
> > +		initialized = true;
> > +	}
> > +
> >  	while (*name != '\0') {
> >  		if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0)
> >  			return false;
> > -- 
> > 1.8.3.1
> >