[PATCH v4] telemetry: remove non-portable array initialization syntax
Tyler Retzlaff
roretzla at linux.microsoft.com
Tue Apr 4 20:09:16 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.ananyev at huawei.com>
Suggested-by: Bruce Richardson <bruce.richardson at intel.com>
Signed-off-by: Tyler Retzlaff <roretzla at linux.microsoft.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..0dc091a 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-alpha-numeric characters allowed in names */
+ 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