Hi all: these lines of program cause a segfault on my Linux machine:
/* testptr.c */
/* gcc -o testptr -Wall -g testptr.c */
int main() {
char *name = "Giuliano";
*name = 'X'; //here I get a seg. fault
return 0;
}
I've tried to found the bug using GDB:
gdb testptr
Starting program: testptr
Breakpoint 1, main () at testptr.c:2
2 char *name = "Giuliano";
(gdb) step
3 *name = 'X';
(gdb) step
4 return 0;
(gdb) print name
$1 = 0x80483e8 "Xiuliano"
(gdb) step
5 }
(gdb) step
0x400397f7 in __libc_start_main () from /lib/i686/libc.so.6
(gdb) step
Single stepping until exit from function __libc_start_main,
which has no line number information.
Program exited normally. (No seg. fault !!!!!!!!!!!!!!)
So, where is the problem?
Thank you
Giuliano
Segmentation fault: where is the bug?
Moderators: kenneth, sbroam, TheKrikkitWars, Mike W., Sir Adam, KNeal, PAC, adamin
-
- CBoats Addict
- Posts: 350
- Joined: Mon Oct 06, 2003 5:47 pm
- Location: Vancouver Island
- Contact: