[Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S)

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu May 26 18:35:00 GMT 2016


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

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
That example is just taken straight from the WG14 document I linked to. Maybe
the compiler should also be able to presume that the allocation is intended for
struct S1 if you do:

        struct S1 *p = malloc(sizeof(p));

but I wanted to suggest following exactly what the secure coding guidelines
require.


More information about the Gcc-bugs mailing list