[Bug malloc/25401] pvalloc must not have __attribute_alloc_size__

jakub at redhat dot com sourceware-bugzilla@sourceware.org
Thu Jan 16 18:03:00 GMT 2020


https://sourceware.org/bugzilla/show_bug.cgi?id=25401

--- Comment #1 from Jakub Jelinek <jakub at redhat dot com> ---
Short example can be something like:
#include <malloc.h>
#include <string.h>

char *q;

int
main ()
{
  char *p = (char *) pvalloc (5);
  if (p == NULL)
    return 0;
  memcpy (p, "abcdefgh", 8);
  q = p;
  return 0;
}
with gcc trunk -O2 -W -Wall:
/tmp/1.c: In function ‘main’:
/tmp/1.c:12:3: warning: ‘memcpy’ writing 8 bytes into a region of size 5
[-Wstringop-overflow=]
   12 |   memcpy (p, "abcdefgh", 8);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/1.c:9:22: note: at offset 0 to an object with size 5 allocated by
‘pvalloc’ here
    9 |   char *p = (char *) pvalloc (5);
      |                      ^~~~~~~~~~~
is reported, although the program is valid (well, relies on pagesize at least 8
bytes, which is quite reasonable assumption).

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list