This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S)
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 26 May 2016 17:52:52 +0000
- Subject: [Bug c/71219] Warn about (struct S*)malloc(n) where n < sizeof(struct S)
- Auto-submitted: auto-generated
- References: <bug-71219-4 at http dot gcc dot gnu dot org/bugzilla/>
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.