This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/25702] feature request: generate a warning for sizeof on a pointer
- 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: Sat, 21 May 2016 17:23:01 +0000
- Subject: [Bug c/25702] feature request: generate a warning for sizeof on a pointer
- Auto-submitted: auto-generated
- References: <bug-25702-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25702
--- Comment #14 from Jonathan Wakely <redi at gcc dot gnu.org> ---
See PR 71219 and the TC it links to. The suggestion is to warn for
(T*)malloc(n) where n < sizeof(T) i.e. when there is enough context to infer
that what was intended was malloc(sizeof(T)). The occurrence of sizeof(p) in
the example is not essential to the point, it's just a common way that the bug
happens.