bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] regex: use C99-style array arg syntax


From: Bruno Haible
Subject: Re: [PATCH] regex: use C99-style array arg syntax
Date: Fri, 27 Aug 2021 01:48:00 +0200

Paul Eggert wrote:
> +#if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
> +     && !defined __STDC_NO_VLA__)
> +# define __ARG_NELTS(n) n
> +#else
> +# define __ARG_NELTS(n)
> +#endif

I would suggest to add a condition __GNUC__ >= 11 in the #if.

Rationale: GCC version 10 provides reasonable diagnostics with
the __access__ attribute, but not with the VLA.

====================== foo.c ======================

int foo1 (int n, int a[])
  __attribute__ ((__access__ (read_only, 2, 1)));

int foo1 (int n, int a[])
{
  return a[0] + a[n-1];
}

int foo2 (int n, int a[static n]);

int foo2 (int n, int a[static n])
{
  return a[0] + a[n-1];
}

void bar (int x)
{
  int arr[4] = { 1, 2, 3, 4 };
  foo1 (4, arr);
  foo1 (5, arr);
  foo2 (4, arr);
  foo2 (5, arr);
}
===================================================

$ gcc-version 10.3.0 -Wall -S foo.c
foo.c: In function 'bar':
foo.c:21:3: warning: 'foo1' reading 20 bytes from a region of size 16 
[-Wstringop-overflow=]
   21 |   foo1 (5, arr);
      |   ^~~~~~~~~~~~~
foo.c:5:5: note: in a call to function 'foo1' declared with attribute 
'read_only (2, 1)'
    5 | int foo1 (int n, int a[])
      |     ^~~~

$ gcc-version 11.2.0 -Wall -S foo.c
foo.c: In function 'bar':
foo.c:21:3: warning: 'foo1' reading 20 bytes from a region of size 16 
[-Wstringop-overread]
   21 |   foo1 (5, arr);
      |   ^~~~~~~~~~~~~
foo.c:19:7: note: source object 'arr' of size 16
   19 |   int arr[4] = { 1, 2, 3, 4 };
      |       ^~~
foo.c:5:5: note: in a call to function 'foo1' declared with attribute 'access 
(read_only, 2, 1)'
    5 | int foo1 (int n, int a[])
      |     ^~~~
foo.c:23:3: warning: 'foo2' accessing 20 bytes in a region of size 16 
[-Wstringop-overflow=]
   23 |   foo2 (5, arr);
      |   ^~~~~~~~~~~~~
foo.c:23:3: note: referencing argument 2 of type 'int *'
foo.c:12:5: note: in a call to function 'foo2'
   12 | int foo2 (int n, int a[static n])
      |     ^~~~

Bruno






reply via email to

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