public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/55791] New: gcc fails to detect wrong type in sizeof in malloc
@ 2012-12-22 17:33 dcb314 at hotmail dot com
2012-12-22 17:57 ` [Bug c/55791] " pinskia at gcc dot gnu.org
2014-02-06 7:28 ` mpolacek at gcc dot gnu.org
0 siblings, 2 replies; 3+ messages in thread
From: dcb314 at hotmail dot com @ 2012-12-22 17:33 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791
Bug #: 55791
Summary: gcc fails to detect wrong type in sizeof in malloc
Classification: Unclassified
Product: gcc
Version: 4.8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: dcb314@hotmail.com
Given the following code, culled from customer code,
# include <stdlib.h>
extern void g(char *);
void f()
{
char *p;
// wrong type in sizeof in malloc
p = (char *) malloc( 10 * sizeof( char *));
g(p);
}
gcc can't detect that the malloc line should be something closer to
p = (char *) malloc( 10 * sizeof( char));
i.e. the type in the sizeof expression must be the same as (or
at very least the same size as) the type of destination buffer.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/55791] gcc fails to detect wrong type in sizeof in malloc
2012-12-22 17:33 [Bug c/55791] New: gcc fails to detect wrong type in sizeof in malloc dcb314 at hotmail dot com
@ 2012-12-22 17:57 ` pinskia at gcc dot gnu.org
2014-02-06 7:28 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-12-22 17:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |diagnostic
Severity|normal |enhancement
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-12-22 17:57:02 UTC ---
I think for GCC it is hard to detect this as sizeof is changed into a constant
integer early on.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/55791] gcc fails to detect wrong type in sizeof in malloc
2012-12-22 17:33 [Bug c/55791] New: gcc fails to detect wrong type in sizeof in malloc dcb314 at hotmail dot com
2012-12-22 17:57 ` [Bug c/55791] " pinskia at gcc dot gnu.org
@ 2014-02-06 7:28 ` mpolacek at gcc dot gnu.org
1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-02-06 7:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55791
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mpolacek at gcc dot gnu.org
--- Comment #2 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
We have -Wsizeof-pointer-memaccess warning for memcpy/memmove/memcmp/..., but I
don't think we can do something about malloc.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-02-06 7:28 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-22 17:33 [Bug c/55791] New: gcc fails to detect wrong type in sizeof in malloc dcb314 at hotmail dot com
2012-12-22 17:57 ` [Bug c/55791] " pinskia at gcc dot gnu.org
2014-02-06 7:28 ` mpolacek at gcc dot gnu.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).