public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38575] New: free() accept argument that has the same name with standard/builtin function
@ 2008-12-19 3:11 m dot shulhan at gmail dot com
2008-12-19 3:17 ` [Bug c/38575] " pinskia at gcc dot gnu dot org
2008-12-19 3:20 ` [Bug middle-end/38575] " pinskia at gcc dot gnu dot org
0 siblings, 2 replies; 3+ messages in thread
From: m dot shulhan at gmail dot com @ 2008-12-19 3:11 UTC (permalink / raw)
To: gcc-bugs
Any variable that has the same name with standard/builtin function name will be
accepted by free parameter.
example of code,
>>>
#include <stdlib.h>
int main(int argc, char *argv[])
{
free(rand);
return 0;
}
<<<
This sample code will success on compile,
$ gcc -Wall -g -O0 free-bug.c
but error on run,
$ ./a.out
*** glibc detected *** ./a.out: free(): invalid pointer: 0x08048364 ***
======= Backtrace: =========
/lib/libc.so.6[0xb7ee94b6]
/lib/libc.so.6(cfree+0x89)[0xb7eeb179]
./a.out[0x8048421]
/lib/libc.so.6(__libc_start_main+0xe0)[0xb7e98fe0]
./a.out[0x80483a1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:03 7946378
/home/rv77ax/doc/sandbox/c/a.out
08049000-0804a000 r--p 00000000 08:03 7946378
/home/rv77ax/doc/sandbox/c/a.out
0804a000-0804b000 rw-p 00001000 08:03 7946378
/home/rv77ax/doc/sandbox/c/a.out
0804b000-0806c000 rw-p 0804b000 00:00 0 [heap]
b7e76000-b7e80000 r-xp 00000000 08:01 817696 /lib/libgcc_s.so.1
b7e80000-b7e82000 rw-p 00009000 08:01 817696 /lib/libgcc_s.so.1
b7e82000-b7e83000 rw-p b7e82000 00:00 0
b7e83000-b7fb0000 r-xp 00000000 08:01 817612 /lib/libc-2.6.1.so
b7fb0000-b7fb1000 r--p 0012c000 08:01 817612 /lib/libc-2.6.1.so
b7fb1000-b7fb3000 rw-p 0012d000 08:01 817612 /lib/libc-2.6.1.so
b7fb3000-b7fb6000 rw-p b7fb3000 00:00 0
b7fcb000-b7fcc000 rw-p b7fcb000 00:00 0
b7fcc000-b7fe6000 r-xp 00000000 08:01 819693 /lib/ld-2.6.1.so
b7fe6000-b7fe8000 rw-p 0001a000 08:01 819693 /lib/ld-2.6.1.so
bfd0a000-bfd20000 rw-p bfd0a000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Aborted
--
Summary: free() accept argument that has the same name with
standard/builtin function
Product: gcc
Version: 4.2.1
Status: UNCONFIRMED
Severity: minor
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: m dot shulhan at gmail dot com
GCC build triplet: -Wall -g -O0
GCC host triplet: i586-suse-linux
GCC target triplet: i586-suse-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38575
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/38575] free() accept argument that has the same name with standard/builtin function
2008-12-19 3:11 [Bug c/38575] New: free() accept argument that has the same name with standard/builtin function m dot shulhan at gmail dot com
@ 2008-12-19 3:17 ` pinskia at gcc dot gnu dot org
2008-12-19 3:20 ` [Bug middle-end/38575] " pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-19 3:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-12-19 03:16 -------
Yes you are passing free a function pointer. a function decays to a function
pointer and an implicit conversion to void* happens.
If you use -pedantic you get an error message as a function pointer cannot be
converted to void* in standard C:
t.c:4: error: ISO C forbids passing argument 1 of 'free' between function
pointer and 'void *'
/usr/include/stdlib.h:159: note: expected 'void *' but argument is of type 'int
(*)(void)'
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38575
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug middle-end/38575] free() accept argument that has the same name with standard/builtin function
2008-12-19 3:11 [Bug c/38575] New: free() accept argument that has the same name with standard/builtin function m dot shulhan at gmail dot com
2008-12-19 3:17 ` [Bug c/38575] " pinskia at gcc dot gnu dot org
@ 2008-12-19 3:20 ` pinskia at gcc dot gnu dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-19 3:20 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-12-19 03:18 -------
Now maybe maybe_emit_free_warning should be enhanced to warn about this.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|minor |enhancement
Component|c |middle-end
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38575
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-12-19 3:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-19 3:11 [Bug c/38575] New: free() accept argument that has the same name with standard/builtin function m dot shulhan at gmail dot com
2008-12-19 3:17 ` [Bug c/38575] " pinskia at gcc dot gnu dot org
2008-12-19 3:20 ` [Bug middle-end/38575] " 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).