This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/17246] New: Feature request: optional malloc type warning
- From: "Gyro at zeta-soft dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 31 Aug 2004 04:59:19 -0000
- Subject: [Bug c/17246] New: Feature request: optional malloc type warning
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
Hi,
It would be very nice to have an option to check the return type of `malloc'.
Most calls to malloc fit this pattern:
struct frob *P;
P = malloc(sizeof(struct frob));
or
P = malloc(N * sizeof(struct frob));
It's not too hard to accidentally write, for example
P = malloc(N * sizeof(struct frob *));
It would be nice to have a `-Wmalloc-type' option, say, that would recognize
instances of the common patterns and check that the type being allocated matched
the type being assigned to. (Whether it should be activated by `-Wall' is not
clear; it depends on the false positive rate, I suppose.)
For this to be completely useful, there will also have to be some way to specify
the name of the allocation routine (`malloc' by default). One of the primary
uses I would have for it, for instance, would be on Linux kernel code, which
uses `kmalloc'.
It's possible I could be persuaded to tackle this myself, but since I haven't
hacked on GCC before it would be nice to have a clue where to start and what
approach to take... five minutes of your time could save me hours.
--
Summary: Feature request: optional malloc type warning
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Gyro at zeta-soft dot com
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17246