A
anirbid.banerjee
#include <stdlib.h>
#include <stdio.h>
int main(){
char *ptr = "hello";
ptr = (char *)realloc (ptr,(size_t) 10 * sizeof (char ));
printf ("\n %s", ptr);
return 0;
}
___________________________________
The above program while execution dumps a stack trace and exits. This
is the detailed error message.
*** glibc detected *** ./try: realloc(): invalid pointer: 0x080484b0
***
======= Backtrace: =========
/lib/libc.so.6(realloc+0x38e)[0x94aa3e]
/lib/libc.so.6[0x94ab81]
/lib/libc.so.6(realloc+0x3c)[0x94a6ec]
../try[0x80483af]
/lib/libc.so.6(__libc_start_main+0xdc)[0x8f6f2c]
../try[0x8048301]
======= Memory map: ========
00295000-00296000 r-xp 00295000 00:00 0 [vdso]
008c0000-008d9000 r-xp 00000000 08:02 163372 /lib/ld-2.5.so
008d9000-008da000 r-xp 00018000 08:02 163372 /lib/ld-2.5.so
008da000-008db000 rwxp 00019000 08:02 163372 /lib/ld-2.5.so
008e1000-00a18000 r-xp 00000000 08:02 163373 /lib/libc-2.5.so
00a18000-00a1a000 r-xp 00137000 08:02 163373 /lib/libc-2.5.so
00a1a000-00a1b000 rwxp 00139000 08:02 163373 /lib/libc-2.5.so
00a1b000-00a1e000 rwxp 00a1b000 00:00 0
00cc7000-00cd2000 r-xp 00000000 08:02 163382 /lib/
libgcc_s-4.1.1-20061011.so.1
00cd2000-00cd3000 rwxp 0000a000 08:02 163382 /lib/
libgcc_s-4.1.1-20061011.so.1
08048000-08049000 r-xp 00000000 08:08 288064 /home/subh/try
08049000-0804a000 rw-p 00000000 08:08 288064 /home/subh/try
08a5c000-08a7d000 rw-p 08a5c000 00:00 0
b7fd4000-b7fd5000 rw-p b7fd4000 00:00 0
b7ff0000-b7ff1000 rw-p b7ff0000 00:00 0
bfd49000-bfd5f000 rw-p bfd49000 00:00 0 [stack]
Aborted
____________________________________________________
I don't know what is going wrong. Please explain.
Thanks
Anirbid
#include <stdio.h>
int main(){
char *ptr = "hello";
ptr = (char *)realloc (ptr,(size_t) 10 * sizeof (char ));
printf ("\n %s", ptr);
return 0;
}
___________________________________
The above program while execution dumps a stack trace and exits. This
is the detailed error message.
*** glibc detected *** ./try: realloc(): invalid pointer: 0x080484b0
***
======= Backtrace: =========
/lib/libc.so.6(realloc+0x38e)[0x94aa3e]
/lib/libc.so.6[0x94ab81]
/lib/libc.so.6(realloc+0x3c)[0x94a6ec]
../try[0x80483af]
/lib/libc.so.6(__libc_start_main+0xdc)[0x8f6f2c]
../try[0x8048301]
======= Memory map: ========
00295000-00296000 r-xp 00295000 00:00 0 [vdso]
008c0000-008d9000 r-xp 00000000 08:02 163372 /lib/ld-2.5.so
008d9000-008da000 r-xp 00018000 08:02 163372 /lib/ld-2.5.so
008da000-008db000 rwxp 00019000 08:02 163372 /lib/ld-2.5.so
008e1000-00a18000 r-xp 00000000 08:02 163373 /lib/libc-2.5.so
00a18000-00a1a000 r-xp 00137000 08:02 163373 /lib/libc-2.5.so
00a1a000-00a1b000 rwxp 00139000 08:02 163373 /lib/libc-2.5.so
00a1b000-00a1e000 rwxp 00a1b000 00:00 0
00cc7000-00cd2000 r-xp 00000000 08:02 163382 /lib/
libgcc_s-4.1.1-20061011.so.1
00cd2000-00cd3000 rwxp 0000a000 08:02 163382 /lib/
libgcc_s-4.1.1-20061011.so.1
08048000-08049000 r-xp 00000000 08:08 288064 /home/subh/try
08049000-0804a000 rw-p 00000000 08:08 288064 /home/subh/try
08a5c000-08a7d000 rw-p 08a5c000 00:00 0
b7fd4000-b7fd5000 rw-p b7fd4000 00:00 0
b7ff0000-b7ff1000 rw-p b7ff0000 00:00 0
bfd49000-bfd5f000 rw-p bfd49000 00:00 0 [stack]
Aborted
____________________________________________________
I don't know what is going wrong. Please explain.
Thanks
Anirbid