From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DEC3A428C5; Mon, 3 Apr 2023 20:47:48 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C024641153; Mon, 3 Apr 2023 20:47:44 +0200 (CEST) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id EC05040A7E for ; Mon, 3 Apr 2023 20:47:41 +0200 (CEST) Received: by linux.microsoft.com (Postfix, from userid 1086) id 32958210CBF2; Mon, 3 Apr 2023 11:47:41 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 32958210CBF2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1680547661; bh=KzrpnChj+Fw04RMR2/32FVh7ZJUZnpP0jbiqpTfdaF0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUlkQ0mQnPSu4gmOnPSnZCNBJFDF9xjNTE9AL938oyCdc/QnUVjjjbAkImrtHaTEb Tl8x0fBrKAJ4Bhm2NBmcA9EOqB7HCCaWmE0vYqjup2thsgEoF77RIP5KqpKvSbj+A+ BPNvUo7+uJi0vSvcJyko6MX5GbbNQuugoIuPTgLg= From: Tyler Retzlaff To: dev@dpdk.org Cc: ciara.power@intel.com, bruce.richardson@intel.com, david.marchand@redhat.com, thomas@monjalon.net, Tyler Retzlaff Subject: [PATCH v2] telemetry: use portable syntax to initialize array Date: Mon, 3 Apr 2023 11:47:40 -0700 Message-Id: <1680547660-14596-2-git-send-email-roretzla@linux.microsoft.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1680547660-14596-1-git-send-email-roretzla@linux.microsoft.com> References: <1680539424-20255-1-git-send-email-roretzla@linux.microsoft.com> <1680547660-14596-1-git-send-email-roretzla@linux.microsoft.com> X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- 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..d845186 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, - }; + static bool initialized; + static char allowed[128]; + + if (!initialized) { + int index; + 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