This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]