public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36970] New: GCC should display a warning when trying to free a static array
@ 2008-07-30 7:13 nair dot sajish at gmail dot com
2008-07-30 8:44 ` [Bug c/36970] " rguenth at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: nair dot sajish at gmail dot com @ 2008-07-30 7:13 UTC (permalink / raw)
To: gcc-bugs
On Tue, Jul 01, 2008 at 11:37:05AM +0000, Joseph S. Myers wrote:
> On Tue, 1 Jul 2008, Michael Meissner wrote:
>
> > On Tue, Jul 01, 2008 at 11:50:58AM +0200, Denys Vlasenko wrote:
> > > On Tuesday 01 July 2008 09:24, Sajish V wrote:
> > > > Thanks for the reply, Denys.
> > > > My question was, why doesn't gcc catch it during compilation? It is clear
> > > > that we are trying to free a variable from stack. Shouldn't gcc flag an
> > > > error for this during compilation?
> >
> > It could. Nobody has written the code to do so, and as they say patches are
> > welcome (assuming you have done the paperwork to legally contribute to GCC).
> > Have you filed a feature request via bugzilla so that it can be tracked?
>
> An error is inappropriate; undefined behavior only occurs on execution of
> the call to free, not on compilation of the program. A warning would be
> fine (as would converting the call to free into an abort).
True enough from a standards point of view. Obviously having a warning would
allow some invalid code to be detected at compilation time.
--
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Thanks for the reply, Denys.
My question was, why doesn't gcc catch it during compilation? It is clear that
we are trying to free a variable from stack. Shouldn't gcc flag an error for
this during compilation?
Regards,
Sajish.
----- Original Message ----
From: Denys Vlasenko <vda.linux@googlemail.com>
To: gcc@gcc.gnu.org
Cc: Sajish V <emailsaju@yahoo.com>
Sent: Tuesday, July 1, 2008 2:44:06 PM
Subject: Re: free (static_array)
On Tuesday 01 July 2008 08:38, Sajish V wrote:
> Hi All,
> Can you please let me know why GCC does not crib when we try to free a static array?
> main ()
> {
> char array[100];
> free (array);
> }
> The above code compiles without any hitch.
> Thanks,
> Sajish.
# ./a.out
*** glibc detected *** ./a.out: free(): invalid pointer: 0xffa8b530 ***
======= Backtrace: =========
/lib/libc.so.6[0xf7ecb7a7]
/lib/libc.so.6(__libc_free+0x79)[0xf7ecc0ad]
./a.out[0x804834e]
/lib/libc.so.6(__libc_start_main+0x138)[0xf7e8da74]
./a.out[0x80482b5]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:06 1315925
/.local/tmp/a.out
08049000-0804a000 rwxp 00000000 08:06 1315925
/.local/tmp/a.out
0804a000-0806b000 rwxp 0804a000 00:00 0 [heap]
f7e6f000-f7e76000 r-xp 00000000 08:05 46193
/app/gcc-3.3.3/lib/libgcc_s.so.1
f7e76000-f7e77000 rwxp 00006000 08:05 46193
/app/gcc-3.3.3/lib/libgcc_s.so.1
f7e77000-f7e78000 rwxp f7e77000 00:00 0
f7e78000-f7f60000 r-xp 00000000 08:0
--
vda
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
Hi All,
Can you please let me know why GCC does not crib when we try to free a static
array?
main ()
{
char array[100];
free (array);
}
The above code compiles without any hitch.
Thanks,
Sajish.
--
Summary: GCC should display a warning when trying to free a
static array
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: nair dot sajish at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/36970] GCC should display a warning when trying to free a static array
2008-07-30 7:13 [Bug c/36970] New: GCC should display a warning when trying to free a static array nair dot sajish at gmail dot com
@ 2008-07-30 8:44 ` rguenth at gcc dot gnu dot org
2008-07-30 13:29 ` jakub at gcc dot gnu dot org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-07-30 8:44 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |diagnostic
Last reconfirmed|0000-00-00 00:00:00 |2008-07-30 08:43:26
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/36970] GCC should display a warning when trying to free a static array
2008-07-30 7:13 [Bug c/36970] New: GCC should display a warning when trying to free a static array nair dot sajish at gmail dot com
2008-07-30 8:44 ` [Bug c/36970] " rguenth at gcc dot gnu dot org
@ 2008-07-30 13:29 ` jakub at gcc dot gnu dot org
2008-07-31 8:05 ` jakub at gcc dot gnu dot org
2008-07-31 8:53 ` jakub at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-07-30 13:29 UTC (permalink / raw)
To: gcc-bugs
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2008-07-30 08:43:26 |2008-07-30 13:27:50
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/36970] GCC should display a warning when trying to free a static array
2008-07-30 7:13 [Bug c/36970] New: GCC should display a warning when trying to free a static array nair dot sajish at gmail dot com
2008-07-30 8:44 ` [Bug c/36970] " rguenth at gcc dot gnu dot org
2008-07-30 13:29 ` jakub at gcc dot gnu dot org
@ 2008-07-31 8:05 ` jakub at gcc dot gnu dot org
2008-07-31 8:53 ` jakub at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-07-31 8:05 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from jakub at gcc dot gnu dot org 2008-07-31 08:04 -------
Subject: Bug 36970
Author: jakub
Date: Thu Jul 31 08:02:49 2008
New Revision: 138362
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=138362
Log:
PR c/36970
* builtins.c (maybe_emit_free_warning): New function.
(expand_builtin): Process BUILT_IN_FREE even at -O0. Call
maybe_emit_free_warning for BUILT_IN_FREE.
* gcc.dg/free-1.c: New test.
* gcc.dg/free-2.c: New test.
Added:
trunk/gcc/testsuite/gcc.dg/free-1.c
trunk/gcc/testsuite/gcc.dg/free-2.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/builtins.c
trunk/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/36970] GCC should display a warning when trying to free a static array
2008-07-30 7:13 [Bug c/36970] New: GCC should display a warning when trying to free a static array nair dot sajish at gmail dot com
` (2 preceding siblings ...)
2008-07-31 8:05 ` jakub at gcc dot gnu dot org
@ 2008-07-31 8:53 ` jakub at gcc dot gnu dot org
3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu dot org @ 2008-07-31 8:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from jakub at gcc dot gnu dot org 2008-07-31 08:52 -------
Implemented on the trunk.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36970
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-07-31 8:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-30 7:13 [Bug c/36970] New: GCC should display a warning when trying to free a static array nair dot sajish at gmail dot com
2008-07-30 8:44 ` [Bug c/36970] " rguenth at gcc dot gnu dot org
2008-07-30 13:29 ` jakub at gcc dot gnu dot org
2008-07-31 8:05 ` jakub at gcc dot gnu dot org
2008-07-31 8:53 ` jakub 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).