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 <roret...@linux.microsoft.com>
Acked-by: Bruce Richardson <bruce.richard...@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. [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] > + 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 >