On 03/10/2011 05:32 PM, Terry Eck wrote:
On 03/10/2011 11:59 AM, Cristian Rodríguez wrote:
the program
#gdb yourprogram (gdb) run (gdb) bt full
post your result to the list.
I added writes to the program. This is the output:
eck@linux-ihxk:/data/DATA/source/account> ./account level 0 level 1 level 2 level 2.1 level 2.1a 74 Segmentation fault ================================
using "gdb account" results in:
eck@linux-ihxk:/data/DATA/source/account> gdb account GNU gdb (GDB) SUSE (7.1-3.12) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i586-suse-linux". For bug reporting instructions, please see: http://www.gnu.org/software/gdb/bugs/... Reading symbols from /data/DATA/source/account/account...done. (gdb) run Starting program: /data/DATA/source/account/account Missing separate debuginfo for /lib/ld-linux.so.2 Try: zypper install -C "debuginfo(build-id)=fbaee3f5e15417f014dc59b0561eb7192ff04c5c" Missing separate debuginfo for /lib/libncurses.so.5 Try: zypper install -C "debuginfo(build-id)=5e4ad4b8f6d215dbb540ba5858512cdfea758f7e" Missing separate debuginfo for /lib/libc.so.6 Try: zypper install -C "debuginfo(build-id)=694c111567b7c83a6f1b97bb28f6687dbd0d3057" Missing separate debuginfo for /lib/libdl.so.2 Try: zypper install -C "debuginfo(build-id)=580696b460256b20961976ebf3b100e5a4c03c10" level 0 level 1 level 2 level 2.1 level 2.1a 74
Program received signal SIGSEGV, Segmentation fault. 0xb7e50158 in vfprintf () from /lib/libc.so.6 (gdb)
The following is a segment of the code with problems. Appears to have a problem with fprintf.
/* ------------------------------------------------------------------ */ put_sort() /* ------------------------------------------------------------------ */ { puts("level 2.1"); fi = fopen("account.srt", "w+"); puts("level 2.1a"); printf("%d\r\n",max_record); fprintf(fi,"%d\r\n",max_record); puts("level 2.1b"); i=1; while (i <= 16) ...
You are not checking that "fi" is valid, i.e. that fopen succeeded. Until proven otherwise my first guess would be that fopen fails. Therefore, fi is NULL and fprintf has a problem with that, which is perfectly OK. Also there is no declaration for "max_record" some evil global int? Robert -- Robert Schweikert MAY THE SOURCE BE WITH YOU Novell-IBM Software Integration Center LINUX Tech Lead rschweikert@novell.com rschweikert@ca.ibm.com 781-464-8147 Novell Making IT Work As One -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org