[PATCH v5] telemetry: remove non-portable array initialization syntax

Tyler Retzlaff roretzla at linux.microsoft.com
Wed Apr 5 20:52:52 CEST 2023


Use of ranges in designated initialization are a non-standard gcc
extension.

Only initialize '_' and '/' elements of the array and filter tests
of characters through name with standard C isalnum before checking
the array.

Suggested-by: Konstantin Ananyev <konstantin.v.ananyev at yandex.ru>
Suggested-by: Bruce Richardson <bruce.richardson at intel.com>
Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.com>
Acked-by: Bruce Richardson <bruce.richardson at intel.com>
---
 lib/telemetry/telemetry_data.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/lib/telemetry/telemetry_data.c b/lib/telemetry/telemetry_data.c
index 2bac2de..0c7187b 100644
--- a/lib/telemetry/telemetry_data.c
+++ b/lib/telemetry/telemetry_data.c
@@ -2,6 +2,7 @@
  * Copyright(c) 2020 Intel Corporation
  */
 
+#include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <inttypes.h>
@@ -152,17 +153,14 @@
 static bool
 valid_name(const char *name)
 {
-	char allowed[128] = {
-			['0' ... '9'] = 1,
-			['A' ... 'Z'] = 1,
-			['a' ... 'z'] = 1,
-			['_'] = 1,
-			['/'] = 1,
-	};
-	while (*name != '\0') {
+	/* non-alphanumeric characters allowed in names */
+	static const char allowed[128] = { ['_'] = 1, ['/'] = 1 };
+
+	for (; *name != '\0'; name++) {
+		if (isalnum(*name))
+			continue;
 		if ((size_t)*name >= RTE_DIM(allowed) || allowed[(int)*name] == 0)
 			return false;
-		name++;
 	}
 	return true;
 }
-- 
1.8.3.1



More information about the dev mailing list