Patchwork ToT glibc build problem with ToT GCC

login
register
mail settings
Submitter Florian Weimer
Date Aug. 30, 2019, 4:18 p.m.
Message ID <87mufq4og4.fsf@oldenburg2.str.redhat.com>
Download mbox | patch
Permalink /patch/34359/
State New
Headers show

Comments

Florian Weimer - Aug. 30, 2019, 4:18 p.m.
* Szabolcs Nagy:

> On 30/08/2019 14:06, Florian Weimer wrote:
>> * Carlos O'Donell:
>> 
>>> Is there a viable solution for a static allocation of a structure
>>> that ends in a VLA?
>> 
>> Sure, use an initializer.  Not sure if this breaks anything.  The test
>> suite is clean.
>> 
>> (GNU C obviously didn't support that when the code was written.)
>
> i didn't know an initializer would be enough.
>
>>  
>> -	replace[0].nbytes = 1;
>> -	replace[0].bytes[0] = '?';
>> -	replace[0].bytes[1] = '\0';
>> -	ctype->mboutdigits[cnt] = &replace[0];
>> +	static const struct charseq replace =
>> +	  {
>> +	     .nbytes = 1,
>> +	     .bytes = { '\0' },
>> +	  };
>> +	ctype->mboutdigits[cnt] = (struct charseq *) &replace;
>>        }
>
> is it ok to change {'?','\0'} to {'\0'} ?

Ah, my mistake.  It should be "?", I suppose.

Thanks,
Florian

localedef: Use initializer for flexible array member [BZ #24950]

2019-08-30  Florian Weimer  <fweimer@redhat.com>

	[BZ #24950]
	* locale/programs/charmap.h (struct charseq): Turn bytes into a
	flexible array member.
	* locale/programs/ld-ctype.c (ctype_finish): Use initializer for
	replace.
Szabolcs Nagy - Sept. 3, 2019, 9:51 a.m.
On 30/08/2019 17:18, Florian Weimer wrote:
> 

> localedef: Use initializer for flexible array member [BZ #24950]

> 


i would mention that you put the struct in .rodata,
that is a non-obvious change.

i'm fine with using gcc extension for the initializer.
i think the union solution is a bit safer though.
either way, it would be nice to fix this build error.

> 2019-08-30  Florian Weimer  <fweimer@redhat.com>

> 

> 	[BZ #24950]

> 	* locale/programs/charmap.h (struct charseq): Turn bytes into a

> 	flexible array member.

> 	* locale/programs/ld-ctype.c (ctype_finish): Use initializer for

> 	replace.

> 

> diff --git a/locale/programs/charmap.h b/locale/programs/charmap.h

> index 870a9e9577..70db330d29 100644

> --- a/locale/programs/charmap.h

> +++ b/locale/programs/charmap.h

> @@ -60,7 +60,7 @@ struct charseq

>    const char *name;

>    uint32_t ucs4;

>    int nbytes;

> -  unsigned char bytes[0];

> +  unsigned char bytes[];

>  };

>  

>  

> diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c

> index cfc9c43fd5..9123f64a56 100644

> --- a/locale/programs/ld-ctype.c

> +++ b/locale/programs/ld-ctype.c

> @@ -842,8 +842,6 @@ no input digits defined and none of the standard names in the charmap"));

>    for (cnt = 0; cnt < 10; ++cnt)

>      if (ctype->mboutdigits[cnt] == NULL)

>        {

> -	static struct charseq replace[2];

> -

>  	if (!warned)

>  	  {

>  	    record_error (0, 0, _("\

> @@ -851,10 +849,12 @@ not all characters used in `outdigit' are available in the charmap"));

>  	    warned = 1;

>  	  }

>  

> -	replace[0].nbytes = 1;

> -	replace[0].bytes[0] = '?';

> -	replace[0].bytes[1] = '\0';

> -	ctype->mboutdigits[cnt] = &replace[0];

> +	static const struct charseq replace =

> +	  {

> +	     .nbytes = 1,

> +	     .bytes = "?",

> +	  };

> +	ctype->mboutdigits[cnt] = (struct charseq *) &replace;

>        }

>  

>    warned = 0;

>

Patch

diff --git a/locale/programs/charmap.h b/locale/programs/charmap.h
index 870a9e9577..70db330d29 100644
--- a/locale/programs/charmap.h
+++ b/locale/programs/charmap.h
@@ -60,7 +60,7 @@  struct charseq
   const char *name;
   uint32_t ucs4;
   int nbytes;
-  unsigned char bytes[0];
+  unsigned char bytes[];
 };
 
 
diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
index cfc9c43fd5..9123f64a56 100644
--- a/locale/programs/ld-ctype.c
+++ b/locale/programs/ld-ctype.c
@@ -842,8 +842,6 @@  no input digits defined and none of the standard names in the charmap"));
   for (cnt = 0; cnt < 10; ++cnt)
     if (ctype->mboutdigits[cnt] == NULL)
       {
-	static struct charseq replace[2];
-
 	if (!warned)
 	  {
 	    record_error (0, 0, _("\
@@ -851,10 +849,12 @@  not all characters used in `outdigit' are available in the charmap"));
 	    warned = 1;
 	  }
 
-	replace[0].nbytes = 1;
-	replace[0].bytes[0] = '?';
-	replace[0].bytes[1] = '\0';
-	ctype->mboutdigits[cnt] = &replace[0];
+	static const struct charseq replace =
+	  {
+	     .nbytes = 1,
+	     .bytes = "?",
+	  };
+	ctype->mboutdigits[cnt] = (struct charseq *) &replace;
       }
 
   warned = 0;