bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: -Wvla vs dcnpgettext_expr's VLA decl


From: Bruno Haible
Subject: Re: -Wvla vs dcnpgettext_expr's VLA decl
Date: Sat, 3 Dec 2011 18:42:52 +0100
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hi Jim,

> I tried enabling -Wvla for coreutils and found that it provoked hundreds
> of warnings, all due to this:
> 
>     ../lib/gettext.h:262:3: error: variable length array 'msg_ctxt_id'\
>     is used [-Werror=vla]
> 
> That comes from this inline function from gettext.h:
> 
>     static const char *
>     dcnpgettext_expr (const char *domain,
>                       const char *msgctxt, const char *msgid,
>                       const char *msgid_plural, unsigned long int n,
>                       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
>     ...

Yes, as you can see this code uses variable-length arrays only
when the compiler supports it.

> Do we have a guarantee that that array dimension is reasonable?

Yes. While msgctxt and msgid normally rarely exceed 1 KB (because
of the principle to split at paragraph boundaries, so that translators
can compare an old and a new msgid, for msgids with plural, the
string is most often only a single sentence, that is, rarely larger
than 200 bytes.

> Have you compared the trade-offs of VLA-vs-malloc here?

Yes I did.

The problem is that the compiler does not know that I did.

You may want to propose a #pragma diagnostic ignore patch.

Bruno
-- 
In memoriam Rudolf Slánský <http://en.wikipedia.org/wiki/Rudolf_Slánský>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]