public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/17246] New: Feature request: optional malloc type warning
@ 2004-08-31  4:59 Gyro at zeta-soft dot com
  2004-08-31  5:12 ` [Bug c/17246] " pinskia at gcc dot gnu dot org
  0 siblings, 1 reply; 2+ messages in thread
From: Gyro at zeta-soft dot com @ 2004-08-31  4:59 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/17246] Feature request: optional malloc type warning
  2004-08-31  4:59 [Bug c/17246] New: Feature request: optional malloc type warning Gyro at zeta-soft dot com
@ 2004-08-31  5:12 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-08-31  5:12 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-08-31 05:12 -------
Really this has no use, try a program like lint which should catch some of these errors.  We are not here 
to say what you really meant.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17246


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-08-31  5:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31  4:59 [Bug c/17246] New: Feature request: optional malloc type warning Gyro at zeta-soft dot com
2004-08-31  5:12 ` [Bug c/17246] " pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).