https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97023

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
Implemented in r11-3827.  GCC 11 diagnoses both invalid calls.  With
-Warray-bounds:

$ gcc -O2 -S -Wall pr97023.c
pr97023.c: In function ‘f’:
pr97023.c:5:13: warning: ‘__builtin_memcpy’ writing 5 bytes into a region of
size 4 [-Wstringop-overflow=]
    5 |   void *p = __builtin_stpcpy (a, "123");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
pr97023.c:1:6: note: at offset 3 to object ‘a’ with size 7 declared here
    1 | char a[7];
      |      ^
pr97023.c: In function ‘g’:
pr97023.c:13:7: warning: ‘__builtin_mempcpy’ forming offset 4 is out of the
bounds [0, 4] [-Warray-bounds]
   13 |   p = __builtin_mempcpy (p, "4567", 5);    // missing warning
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


and without:

$ gcc -O2 -S -Wall -Wno-array-bounds pr97023.c
pr97023.c: In function ‘f’:
pr97023.c:5:13: warning: ‘__builtin_memcpy’ writing 5 bytes into a region of
size 4 [-Wstringop-overflow=]
    5 |   void *p = __builtin_stpcpy (a, "123");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~
pr97023.c:1:6: note: at offset 3 to object ‘a’ with size 7 declared here
    1 | char a[7];
      |      ^
pr97023.c: In function ‘g’:
pr97023.c:13:7: warning: ‘__builtin_mempcpy’ writing 5 bytes into a region of
size 4 overflows the destination [-Wstringop-overflow=]
   13 |   p = __builtin_mempcpy (p, "4567", 5);    // missing warning
      |       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pr97023.c:1:6: note: at offset 3 into destination object ‘a’
    1 | char a[7];
      |      ^

Reply via email to