From: Bruno Haible Date: Fri, 26 May 2023 22:25:12 +0000 (+0200) Subject: Silence a gcc warning "array subscript ... is partly outside array bounds". X-Git-Tag: v0.22~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39fe8f24c15d211ba1e04100b03fe2f4a0676e2d;p=thirdparty%2Fgettext.git Silence a gcc warning "array subscript ... is partly outside array bounds". * 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. --- diff --git a/autogen.sh b/autogen.sh index 76a276bdb..e72f445c4 100755 --- a/autogen.sh +++ b/autogen.sh @@ -159,6 +159,7 @@ if ! $skip_gnulib; then execute filename findprog + flexmember fnmatch fopen free-posix diff --git a/gettext-tools/src/xg-arglist-parser.c b/gettext-tools/src/xg-arglist-parser.c index c41e92116..dedb0baef 100644 --- a/gettext-tools/src/xg-arglist-parser.c +++ b/gettext-tools/src/xg-arglist-parser.c @@ -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; diff --git a/gettext-tools/src/xg-arglist-parser.h b/gettext-tools/src/xg-arglist-parser.h index e2f754e45..9f2dedca0 100644 --- a/gettext-tools/src/xg-arglist-parser.h +++ b/gettext-tools/src/xg-arglist-parser.h @@ -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.