]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
localedef: Use initializer for flexible array member [BZ #24950]
authorFlorian Weimer <fweimer@redhat.com>
Tue, 3 Sep 2019 12:01:39 +0000 (14:01 +0200)
committerFlorian Weimer <fweimer@redhat.com>
Tue, 3 Sep 2019 12:01:47 +0000 (14:01 +0200)
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.

ChangeLog
locale/programs/charmap.h
locale/programs/ld-ctype.c

index 67ec991785f16582f2af98f0ea9879371bcc5ad8..e215c4a717ba8ba3836092d1b5afd572c988f1da 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-09-03  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.
+
 2019-09-02  Florian Weimer  <fweimer@redhat.com>
 
        * misc/tst-mntent-autofs.c: New file.
index 870a9e9577d8bd9d8a55ed5535855086b6fe7beb..70db330d291a88e22e8b14bd79cfcd4e047438ce 100644 (file)
@@ -60,7 +60,7 @@ struct charseq
   const char *name;
   uint32_t ucs4;
   int nbytes;
-  unsigned char bytes[0];
+  unsigned char bytes[];
 };
 
 
index cfc9c43fd58235a3b3ee630cc40afc39fe108c05..9123f64a56f6306e1a540d9be25d1093a36840b7 100644 (file)
@@ -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;