https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119749
Bug ID: 119749 Summary: Functions with attribute malloc only warn of possibly-NULL use if attribute has a deallocator Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: analyzer Assignee: dmalcolm at gcc dot gnu.org Reporter: pietro.gcc at sociotechnical dot xyz Target Milestone: --- When adding "__attribute__ ((__malloc__))" to a function the analyzer doesn't warn that the function may return a null pointer. If I add a deallocator to the attribute then the analyzer warns about the null pointer. In the reproducer bellow it won't warn for "use_my_malloc" but will for the other functions, including the one that uses the system malloc. I'm using a build from trunk and running "gcc -fanalyzer -c test.c -o test.o". -------- #include <stdlib.h> extern void do_something (int*) __attribute__ ((__nonnull__)); extern void *my_malloc (size_t) __attribute__ ((__malloc__)); extern void *my_malloc_free (size_t) __attribute__ ((__malloc__, __malloc__ (free))); extern void *my_malloc_free1 (size_t) __attribute__ ((__malloc__ (free, 1))); int use_my_malloc () { int *something; something = (int *)my_malloc (16); do_something (something); return 0; } int use_my_malloc_free () { int *something; something = (int *)my_malloc_free (16); do_something (something); return 0; } int use_my_malloc_free1 () { int *something; something = (int *)my_malloc_free1 (16); do_something (something); return 0; } int use_system_malloc () { int *something; something = (int *)malloc (16); do_something (something); return 0; }