From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-4.0 required=3.0 tests=AWL,BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 9D994211B5 for ; Mon, 14 Jan 2019 06:10:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:54757 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1givSP-0004fg-4p for normalperson@yhbt.net; Mon, 14 Jan 2019 01:10:45 -0500 Received: from eggs.gnu.org ([209.51.188.92]:56008) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1givSK-0004fU-GF for bug-gnulib@gnu.org; Mon, 14 Jan 2019 01:10:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1givSJ-0005pb-Fh for bug-gnulib@gnu.org; Mon, 14 Jan 2019 01:10:40 -0500 Received: from mail.magicbluesmoke.com ([82.195.144.49]:45236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1givSH-0005me-Cf for bug-gnulib@gnu.org; Mon, 14 Jan 2019 01:10:38 -0500 Received: from localhost.localdomain (unknown [76.21.115.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.magicbluesmoke.com (Postfix) with ESMTPSA id 337AB9D2B; Mon, 14 Jan 2019 06:10:32 +0000 (GMT) Subject: Re: Correct but unhelpful VLA warning vs. gnulib's gettext.h; can we eliminate the false positive? To: James Youngman , bug-gnulib References: From: =?UTF-8?Q?P=c3=a1draig_Brady?= Message-ID: <8b1499e2-4b89-02b1-f3e0-845072a12796@draigBrady.com> Date: Sun, 13 Jan 2019 22:10:29 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------2594E2CFEA928B614C159D18" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 82.195.144.49 X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Bernhard Voelker Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --------------2594E2CFEA928B614C159D18 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 09/07/11 15:32, James Youngman wrote: > To be clear before we start, gnulib is doing the right thing here. It > contains this code in lib/gettext.h:- >=20 > static const char * > dcpgettext_expr (const char *domain, > const char *msgctxt, const char *msgid, > int category) > { > size_t msgctxt_len =3D strlen (msgctxt) + 1; > size_t msgid_len =3D strlen (msgid) + 1; > const char *translation; > #if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS > char msg_ctxt_id[msgctxt_len + msgid_len]; > #else > char buf[1024]; > char *msg_ctxt_id =3D > (msgctxt_len + msgid_len <=3D sizeof (buf) > ? buf > : (char *) malloc (msgctxt_len + msgid_len)); > if (msg_ctxt_id !=3D NULL) > #endif >=20 >=20 > tl;dr: it uses a variable-length array if we determined that the > compiler supports those. All well and good. But, if we compile the > code with more GCC warnings turned on via the manywarnings module, we > get this result: > In function 'dcpgettext_expr': > /home/james/source/GNU/findutils/git/gnu/findutils/gl/lib/gettext.h:216= : > warning: variable length array 'msg_ctxt_id' is used > In other words, "gcc -Wvla" is issuing a warning for a construct we > know is safe. However, I can't be sure I won't accidentally write > code in the future which is not protected by something similar to > _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS. So I think that -Wvla is a > useful warning flag. >=20 > Is there a way of eliminating this false positive which doesn't force > me to give up -Wvla? I mean, apart from giving up the use of VLAs in > gnulib even when it's safe to use them. We might want to disable use of VLAs even if the compiler supports it, for security reasons (like the Linux kernel now does), or if you didn't want to consider VLA portability in gnulib using projects, as you've suggested. Attached allows one to define GNULIB_NO_VLA to support that, which I've tested in coreutils with: AC_DEFINE([GNULIB_NO_VLA], [1], [Define to 1 to disable use of VLAs]) Note -Wvla is implicitly added by gl_MANYWARN_ALL_GCC, so we don't need any special handling of this option once GNULIB_NO_VLA i= s defined. cheers, P=C3=A1draig --------------2594E2CFEA928B614C159D18 Content-Type: text/x-patch; name="gnulib-no-vla.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gnulib-no-vla.diff" =46rom fb2b401be4d57f035322ebba825292e66db0e999 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?P=3DC3=3DA1draig=3D20Brady?=3D Date: Sun, 13 Jan 2019 22:05:10 -0800 Subject: [PATCH] gettext: support disabling use of VLAs * lib/gettext.h: Disable use of VLAs if GNULIB_NO_VLA is defined --- ChangeLog | 5 +++++ lib/gettext.h | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index d1f0d63..2e87a1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-01-13 P=C3=A1draig Brady + + gettext: support disabling use of VLAs + * lib/gettext.h: Disable use of VLAs if GNULIB_NO_VLA is defined + 2018-12-21 Bruno Haible =20 Assume Autoconf >=3D 2.63. diff --git a/lib/gettext.h b/lib/gettext.h index d5d56ec..a0d854e 100644 --- a/lib/gettext.h +++ b/lib/gettext.h @@ -184,9 +184,10 @@ npgettext_aux (const char *domain, =20 #include =20 -#if (((__GNUC__ >=3D 3 || __GNUG__ >=3D 2) && !defined __STRICT_ANSI__) = \ - /* || (__STDC_VERSION__ =3D=3D 199901L && !defined __HP_cc) - || (__STDC_VERSION__ >=3D 201112L && !defined __STDC_NO_VLA__) *= / ) +#if (!defined GNULIB_NO_VLA \ + && (((__GNUC__ >=3D 3 || __GNUG__ >=3D 2) && !defined __STRICT_ANSI= __) \ + /* || (__STDC_VERSION__ =3D=3D 199901L && !defined __HP_cc) + || (__STDC_VERSION__ >=3D 201112L && !defined __STDC_NO_VLA__) = */ )) # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 1 #else # define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS 0 --=20 2.9.3 --------------2594E2CFEA928B614C159D18--