bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* Correct but unhelpful VLA warning vs. gnulib's gettext.h; can we eliminate the false positive?
@ 2011-07-09 22:32 James Youngman
  2011-07-10  4:47 ` Paul Eggert
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: James Youngman @ 2011-07-09 22:32 UTC (permalink / raw)
  To: bug-gnulib

To be clear before we start, gnulib is doing the right thing here.  It
contains this code in lib/gettext.h:-

static const char *
dcpgettext_expr (const char *domain,
                 const char *msgctxt, const char *msgid,
                 int category)
{
  size_t msgctxt_len = strlen (msgctxt) + 1;
  size_t msgid_len = 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 =
    (msgctxt_len + msgid_len <= sizeof (buf)
     ? buf
     : (char *) malloc (msgctxt_len + msgid_len));
  if (msg_ctxt_id != NULL)
#endif


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:

gcc -std=gnu99 -DHAVE_CONFIG_H -I.
-I/home/james/source/GNU/findutils/git/gnu/findutils/find -I..
-I../gl/lib -I/home/james/source/GNU/findutils/git/gnu/findutils/lib
-I/home/james/source/GNU/findutils/git/gnu/findutils/gl/lib -I../intl
-DLOCALEDIR=\"/usr/local/share/locale\"   -Wall -W -Wformat-y2k
-Wformat-security -Winit-self -Wmissing-include-dirs -Wswitch-enum
-Wunused -Wunknown-pragmas -Wstrict-aliasing -Wstrict-overflow
-Wfloat-equal -Wdeclaration-after-statement -Wshadow
-Wunsafe-loop-optimizations -Wpointer-arith -Wbad-function-cast
-Wcast-qual -Wcast-align -Wwrite-strings -Wlogical-op
-Waggregate-return -Wstrict-prototypes -Wold-style-definition
-Wmissing-prototypes -Wmissing-declarations -Wmissing-noreturn
-Wmissing-format-attribute -Wpacked -Wredundant-decls -Wnested-externs
-Winline -Winvalid-pch -Wlong-long -Wvla -Wvolatile-register-var
-Wdisabled-optimization -Wstack-protector -Woverlength-strings
-Wbuiltin-macro-redefined -Wmudflap -Wpacked-bitfield-compat
-Wsync-nand -Wattributes -Wcoverage-mismatch -Wmultichar
-Wunused-macros -Wno-missing-field-initializers -g -O2 -MT fstype.o
-MD -MP -MF .deps/fstype.Tpo -c -o fstype.o
/home/james/source/GNU/findutils/git/gnu/findutils/find/fstype.c
cc1: warning: ../intl: No such file or directory
In file included from
/home/james/source/GNU/findutils/git/gnu/findutils/find/fstype.c:56:
/home/james/source/GNU/findutils/git/gnu/findutils/gl/lib/gettext.h:
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
/home/james/source/GNU/findutils/git/gnu/findutils/gl/lib/gettext.h:
In function 'dcnpgettext_expr':
/home/james/source/GNU/findutils/git/gnu/findutils/gl/lib/gettext.h:262:
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.

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.

James.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-02-02 22:58 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-09 22:32 Correct but unhelpful VLA warning vs. gnulib's gettext.h; can we eliminate the false positive? James Youngman
2011-07-10  4:47 ` Paul Eggert
2011-07-10  9:16   ` James Youngman
2011-07-11  0:11     ` Paul Eggert
2011-07-11  1:02       ` James Youngman
2011-07-11  1:13         ` Paul Eggert
2011-07-10  9:48 ` Simon Josefsson
2019-01-14  6:10 ` Pádraig Brady
2019-01-15  1:57   ` VLA and alloca Bruno Haible
2019-01-20  4:46     ` Pádraig Brady
2019-01-20 10:19       ` Bruno Haible
2019-01-20 21:03         ` Pádraig Brady
2019-02-02 22:44         ` Paul Eggert
2019-01-20 15:36       ` Bruno Haible
2019-01-24 11:51         ` Tim Rühsen
2019-02-02 22:58           ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).