]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Silence a gcc warning "array subscript ... is partly outside array bounds".
authorBruno Haible <bruno@clisp.org>
Fri, 26 May 2023 22:25:12 +0000 (00:25 +0200)
committerBruno Haible <bruno@clisp.org>
Fri, 26 May 2023 22:26:19 +0000 (00:26 +0200)
* autogen.sh (GNULIB_MODULES_TOOLS_FOR_SRC): Add flexmember.
* gettext-tools/src/xg-arglist-parser.h (struct arglist_parser): Use
FLEXIBLE_ARRAY_MEMBER.
* gettext-tools/src/xg-arglist-parser.c: Include flexmember.h.
(arglist_parser_alloc, arglist_parser_clone): Use FLEXNSIZEOF instead of
hand-made size computations.

autogen.sh
gettext-tools/src/xg-arglist-parser.c
gettext-tools/src/xg-arglist-parser.h

index 76a276bdb0cc874ed2273e31cfcc6ee0db2acac6..e72f445c401ea284a99baf8f9a8a0b71a5750cf8 100755 (executable)
@@ -159,6 +159,7 @@ if ! $skip_gnulib; then
     execute
     filename
     findprog
+    flexmember
     fnmatch
     fopen
     free-posix
index c41e92116daa30c7fd1438e91a6a58d346815b3c..dedb0baef5252357dd5d7b1961d7c1b2f47b9d5f 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "error.h"
 #include "error-progname.h"
+#include "flexmember.h"
 #include "xalloc.h"
 #include "xsize.h"
 
@@ -44,7 +45,7 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
     {
       struct arglist_parser *ap =
         (struct arglist_parser *)
-        xmalloc (offsetof (struct arglist_parser, alternative[0]));
+        xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative, 0));
 
       ap->mlp = mlp;
       ap->keyword = NULL;
@@ -58,9 +59,8 @@ arglist_parser_alloc (message_list_ty *mlp, const struct callshapes *shapes)
     {
       struct arglist_parser *ap =
         (struct arglist_parser *)
-        xmalloc (xsum (sizeof (struct arglist_parser),
-                       xtimes (shapes->nshapes - 1,
-                               sizeof (struct partial_call))));
+        xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative,
+                              shapes->nshapes));
       size_t i;
 
       ap->mlp = mlp;
@@ -104,8 +104,8 @@ arglist_parser_clone (struct arglist_parser *ap)
 {
   struct arglist_parser *copy =
     (struct arglist_parser *)
-    xmalloc (xsum (sizeof (struct arglist_parser) - sizeof (struct partial_call),
-                   xtimes (ap->nalternatives, sizeof (struct partial_call))));
+    xmalloc (FLEXNSIZEOF (struct arglist_parser, alternative,
+                          ap->nalternatives));
   size_t i;
 
   copy->mlp = ap->mlp;
index e2f754e45f9f30b72f666c15861467799785234f..9f2dedca06814de2882d930e896d8059518c41f2 100644 (file)
@@ -1,6 +1,6 @@
 /* Resolving ambiguity of argument lists: Progressive parsing of an
    argument list, keeping track of all possibilities.
-   Copyright (C) 2001-2018 Free Software Foundation, Inc.
+   Copyright (C) 2001-2023 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -66,7 +66,7 @@ struct arglist_parser
   size_t keyword_len;           /* the keyword's length */
   bool next_is_msgctxt;         /* true if the next argument is the msgctxt */
   size_t nalternatives;         /* number of partial_call alternatives */
-  struct partial_call alternative[1]; /* partial_call alternatives */
+  struct partial_call alternative[FLEXIBLE_ARRAY_MEMBER]; /* partial_call alternatives */
 };
 
 /* Creates a fresh arglist_parser recognizing calls.