Help: crash when doing fprintf 
Author Message
 Help: crash when doing fprintf



Quote:
>It crashes deep inside the fprintf.  A trace with the de{*filter*}
>indicates where (main called _fprintf which called _wrtchk which
>called _findbuf which called malloc):

Crashing in malloc is a very strong indication your program corrupted the
heap earlier in its execution. CHeck that your code doesn't write outside
array bounds, use objects after they have been freed or free objects that
weren't allocated by malloc/calloc/realloc.

It is quite normal for stdio functions to call malloc. They typically do
it to allocate the I/O buffer when it is first needed.

--
-----------------------------------------


-----------------------------------------



Fri, 03 Jul 1998 03:00:00 GMT  
 Help: crash when doing fprintf


Quote:

>Hello folks!

>My program crashes when it executes the following statements:

>        char frootn[200]=".",
>         fout[200]  ="";
>        float time;
>        FILE *fp;

How much stack do you have allocated? Have you tried defining some of your
locals (especially large ones) static?

Quote:
>        ....
>    sprintf(fout,"%s/test%-.5g",frootn,time);
>    printf("Outputting to %s...\n",fout);
>    fp=fopen(fout,"w");

I have to figure you've tested this in a de{*filter*} and know that fp != NULL,
but do you know the internal representation of NULL on your machine? No reason
not to test this FILE * in your code.

Quote:
>    fprintf(fp,"Hello\n");

>This is what fp points to at crash time:

>0x40001038  struct FILE {
>    __cnt = 0;
>    __ptr =   00000000;
>    __base =   00000000;
>    __flag = 2;
>    __fileL = 3;
>    __fileH = 0;
>}

>It crashes deep inside the fprintf.  A trace with the de{*filter*}
>indicates where (main called _fprintf which called _wrtchk which
>called _findbuf which called malloc):





0x7b014e6c)
> 4 main (argc = 3, argv = 0x7b033494)    [sfbynorm.c: 556]

>I've never seen anything like that bug before.  I used gcc 2.7.1
>with -Wall -pedantic and get no warnings whatsoever.  With lint the
>only warning I get is a possible pointer alignment problem from the
>2 lines which define (and initialize) frootn[] and fout[], though I
>don't know whether I should take that seriously.

>Anybody have any clue?  Thanks for any help,

>Oliver

Bill

"Whatcha got on?...Your mind?"



Fri, 03 Jul 1998 03:00:00 GMT  
 Help: crash when doing fprintf

Hello folks!

My program crashes when it executes the following statements:

        char frootn[200]=".",
             fout[200]  ="";
        float time;
        FILE *fp;
        ....
        sprintf(fout,"%s/test%-.5g",frootn,time);
        printf("Outputting to %s...\n",fout);
        fp=fopen(fout,"w");
        fprintf(fp,"Hello\n");

This is what fp points to at crash time:

0x40001038  struct FILE {
    __cnt = 0;
    __ptr =   00000000;
    __base =   00000000;
    __flag = 2;
    __fileL = 3;
    __fileH = 0;

Quote:
}

It crashes deep inside the fprintf.  A trace with the de{*filter*}
indicates where (main called _fprintf which called _wrtchk which
called _findbuf which called malloc):





 4 main (argc = 3, argv = 0x7b033494)    [sfbynorm.c: 556]

I've never seen anything like that bug before.  I used gcc 2.7.1
with -Wall -pedantic and get no warnings whatsoever.  With lint the
only warning I get is a possible pointer alignment problem from the
2 lines which define (and initialize) frootn[] and fout[], though I
don't know whether I should take that seriously.

Anybody have any clue?  Thanks for any help,

Oliver
--
  _________________________________........----------------,

 \_|  Condensed-Matter/Quantum-Optics Theory Group           )
   /  Physics Dept University of Toronto -- Canada          /



Fri, 03 Jul 1998 03:00:00 GMT  
 Help: crash when doing fprintf

Quote:

>    printf("Outputting to %s...\n",fout);
>    fp=fopen(fout,"w");
>    fprintf(fp,"Hello\n");
>This is what fp points to at crash time:
>0x40001038  struct FILE {
>    __cnt = 0;
>    __ptr =   00000000;
>    __base =   00000000;

Judging from these values, you are printing to a null pointer.  Have
you checked to see if the file opened, because you aren't in this
code.

Bruce D. Wedding                        Have Compiler, Will Travel!
              Perspicacious Programming Performed Promptly
Katy, Texas, USA, Planet Earth, Milkyway Galaxy, Known Universe



Sat, 04 Jul 1998 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help with fprintf problem

2. [Fwd: Need help with fprintf problem]

3. fPRINTf - please help, urgent

4. fscanf help then fprintf

5. Help: How to print using fprintf

6. fprintf help

7. help with fprintf ()

8. Loadlibrary and HTML Help - Help window crashes

9. Need some help -almost done

10. Help ME Program done except for a little prob

11. almost done.. please help

12. Help I cant C what I am doing wrong

 

 
Powered by phpBB® Forum Software