www.delorie.com/djgpp/bugs/show.cgi   search  
Bug 000218

When Created: 04/28/1998 12:32:10
Against DJGPP version: 2.01
By whom: jnz@thevortex.com
Abstract: fread crash in C++
i open a file for binary read with fopen, and i do (in this order) a fseek,
ftell, fseek, and then an fread.  the program runs fine with the exact same
code in C, but when i compile it as C++, the program crashes.  i used FSDB,
and i found that fread's ret is going to some weird place that is definately
not where it should go.  it crashes 3 instructions later.  this is with
no optimizations at all...just gxx test.cpp -o test.exe.  however, something
i found quite interesting, is that when i add -O1, -O2, or -O3, it runs
absolutely fine.  i'm guessing the bug is in fread's code?

btw, here's some of the code

char *DMA_Buffer;
FILE *f;
int len;

f = fopen("test.raw", "rb");      // test.raw is 41100 bytes
fseek(f, 0, 2);
len = ftell(f);
fseek(f, 0, 0);
fread(DMA_Buffer, len, 1, f);     // heres the buggy line
fclose(f);

Note added: 04/28/1998 13:43:40
By whom: jnz@thevortex.com
after i posted this, i added more to the program, and now it crashes, even
with optimizations on.  only thing i can think of is fread doesn't pop
everything it pushed onto the stack, and its just ret-ing to some crap code.

Note added: 04/15/1999 11:00:38
By whom: eliz@is.elta.co.il
I cannot reproduce this problem, no matter how hard I tried.  It doesn't
crash for me neither in C nor in C++.

Since the source as posted doesn't initialize *DMA_Buffer, I'm gonna
be naughty and claim that this is a programmer's error, at least
until somebody else proves otherwise.

Closed on 04/15/1999 11:00:12: Programmer's error, not a bug.
By whom: eliz@is.elta.co.il



  webmaster     delorie software   privacy  
  Copyright © 2010   by DJ Delorie     Updated Jul 2010