bug-gnulib
[Top][All Lists]
Advanced

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

Re: VLA and alloca


From: Pádraig Brady
Subject: Re: VLA and alloca
Date: Sun, 20 Jan 2019 13:03:15 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 20/01/19 02:19, Bruno Haible wrote:
> Paul,
> 
> Pádraig Brady wrote:
>> I've pushed this with some comments at the current single GNULIB_NO_VLA 
>> usage.
> 
> How about making use of this GNULIB_NO_VLA macro in all places that assume
> VLA syntax? I'm proposing this patch:
> 
> 
> 2019-01-20  Bruno Haible  <address@hidden>
> 
>       vla: Consider GNULIB_NO_VLA.
>       * lib/vla.h (VLA_ELEMS): Define to empty if GNULIB_NO_VLA is defined.
> 
> diff --git a/lib/vla.h b/lib/vla.h
> index f6ebba0..fa5f39a 100644
> --- a/lib/vla.h
> +++ b/lib/vla.h
> @@ -17,10 +17,21 @@
>  
>     Written by Paul Eggert.  */
>  
> -/* A function's argument must point to an array with at least N elements.
> +/* GNULIB_NO_VLA can be defined to disable use of VLAs even if supported.
> +   This relates to the -Wvla and -Wvla-larger-than warnings, enabled in
> +   the default GCC many warnings set.  This allows programs to disable use
> +   of VLAs, which may be unintended, or may be awkward to support portably,
> +   or may have security implications due to non-deterministic stack usage.  
> */
> +
> +/* Types and variables which are variable-length arrays can be used without
> +   particular macros.  */
> +
> +/* VLA_ELEMS is a helper macro used for declaring a function parameter that
> +   is a variable-length array.
> +   A function's argument must point to an array with at least N elements.
>     Example: 'int main (int argc, char *argv[VLA_ELEMS (argc)]);'.  */
>  
> -#ifdef __STDC_NO_VLA__
> +#if defined __STDC_NO_VLA__ || defined GNULIB_NO_VLA
>  # define VLA_ELEMS(n)
>  #else
>  # define VLA_ELEMS(n) static n

+1

thanks,
Pádraig




reply via email to

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