On Fri, 14 Dec 2018 08:38:27 -0800
Jeff Shaw <jeffrey.b.s...@intel.com> wrote:

> Compilers that do not support the C11 standard, or do not implement
> gcc extensions, may not support variable length arrays.
> 
> The code prior to this commit produced the following warning when
> compiled with "-Wvla -std=c90".
> 
>   warning: ISO C90 forbids variable length array ‘array’ [-Wvla]
> 
> This commit removes the variable length array from the PMD debug
> trace function by allocating memory dynamically on the stack using
> alloca().
> 
> Signed-off-by: Jeff Shaw <jeffrey.b.s...@intel.com>
> ---
>  lib/librte_eal/common/include/rte_dev.h | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/librte_eal/common/include/rte_dev.h 
> b/lib/librte_eal/common/include/rte_dev.h
> index a9724dc91..af772872b 100644
> --- a/lib/librte_eal/common/include/rte_dev.h
> +++ b/lib/librte_eal/common/include/rte_dev.h
> @@ -47,22 +47,21 @@ __attribute__((format(printf, 2, 0)))
>  static inline void
>  rte_pmd_debug_trace(const char *func_name, const char *fmt, ...)
>  {
> +     char *buffer;
> +     int buf_len;
>       va_list ap;
>  
>       va_start(ap, fmt);
> +     buf_len = vsnprintf(NULL, 0, fmt, ap) + 1;
> +     va_end(ap);
>  
> -     {
> -             char buffer[vsnprintf(NULL, 0, fmt, ap) + 1];
> +     buffer = (char *)alloca(buf_len);

alloca is void * so cast is not necessary.

You might be able to skip the buffering step entirely by using rte_log
a little more creatively, see how other logging works.

But to go further since rte_pmd_debug_trace is not used anywhere in
current code base in DPDK, it should just be removed.

Reply via email to