hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
From 913d0733e1ed6c0398d8ff7d2dc3ed62e0ff2b4d Mon Sep 17 00:00:00 2001
From: Florian Weimer <fweimer@redhat.com>
Date: Tue, 3 Sep 2019 14:01:39 +0200
Subject: [PATCH 14/19] localedef: Use initializer for flexible array member
 [BZ #24950]
 
struct charseq used a zero-length array instead of a flexible array
member.  This required a strange construct to initialize struct
charseq objects, and GCC 10 warns about that:
 
cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
In file included from programs/repertoire.h:24,
                 from programs/localedef.h:32,
                 from programs/ld-ctype.c:35:
programs/charmap.h:63:17: note: destination object declared here
   63 |   unsigned char bytes[0];
      |                 ^~~~~
cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
programs/charmap.h:63:17: note: destination object declared here
cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
programs/charmap.h:63:17: note: destination object declared here
cc1: error: writing 1 byte into a region of size 0 [-Werror=stringop-overflow=]
programs/charmap.h:63:17: note: destination object declared here
 
The change makes the object physically const, but it is not expected
to be modified.
 
(cherry picked from commit 1471fa556afb428c4a4c46cf5543a4101d5bcf91)
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 locale/programs/charmap.h  |  2 +-
 locale/programs/ld-ctype.c | 12 ++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)
 
diff --git a/locale/programs/charmap.h b/locale/programs/charmap.h
index 870a9e95..70db330d 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 36fd08ba..b4e65c6e 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;
-- 
2.20.1