1From c426ef7486af62ee472ddd78f1c261a975427ccb Mon Sep 17 00:00:00 2001
2From: Florian Weimer <fweimer@redhat.com>
3Date: Tue, 3 Sep 2019 14:01:39 +0200
4Subject: [PATCH 14/20] localedef: Use initializer for flexible array member
5 [BZ #24950]
6
7struct charseq used a zero-length array instead of a flexible array
8member.  This required a strange construct to initialize struct
9charseq objects, and GCC 10 warns about that:
10
11cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
12In file included from programs/repertoire.h:24,
13                 from programs/localedef.h:32,
14                 from programs/ld-ctype.c:35:
15programs/charmap.h:63:17: note: destination object declared here
16   63 |   unsigned char bytes[0];
17      |                 ^~~~~
18cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
19programs/charmap.h:63:17: note: destination object declared here
20cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
21programs/charmap.h:63:17: note: destination object declared here
22cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
23programs/charmap.h:63:17: note: destination object declared here
24
25The change makes the object physically const, but it is not expected
26to be modified.
27
28(cherry picked from commit 1471fa556afb428c4a4c46cf5543a4101d5bcf91)
29Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
30---
31 locale/programs/charmap.h  |  2 +-
32 locale/programs/ld-ctype.c | 12 ++++++------
33 2 files changed, 7 insertions(+), 7 deletions(-)
34
35diff --git a/locale/programs/charmap.h b/locale/programs/charmap.h
36index 66a4385e..a8396cb4 100644
37--- a/locale/programs/charmap.h
38+++ b/locale/programs/charmap.h
39@@ -60,7 +60,7 @@ struct charseq
40   const char *name;
41   uint32_t ucs4;
42   int nbytes;
43-  unsigned char bytes[0];
44+  unsigned char bytes[];
45 };
46
47
48diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
49index f791e6b7..dffe7bf5 100644
50--- a/locale/programs/ld-ctype.c
51+++ b/locale/programs/ld-ctype.c
52@@ -842,8 +842,6 @@ no input digits defined and none of the standard names in the charmap"));
53   for (cnt = 0; cnt < 10; ++cnt)
54     if (ctype->mboutdigits[cnt] == NULL)
55       {
56-	static struct charseq replace[2];
57-
58 	if (!warned)
59 	  {
60 	    record_error (0, 0, _("\
61@@ -851,10 +849,12 @@ not all characters used in `outdigit' are available in the charmap"));
62 	    warned = 1;
63 	  }
64
65-	replace[0].nbytes = 1;
66-	replace[0].bytes[0] = '?';
67-	replace[0].bytes[1] = '\0';
68-	ctype->mboutdigits[cnt] = &replace[0];
69+	static const struct charseq replace =
70+	  {
71+	     .nbytes = 1,
72+	     .bytes = "?",
73+	  };
74+	ctype->mboutdigits[cnt] = (struct charseq *) &replace;
75       }
76
77   warned = 0;
78--
792.20.1
80
81