Mail Archives: djgpp/1994/02/11/18:19:19
Hello world!
After my last mail on go32 crashes wihth IOStream, I've created some simple
programs that crash. I've gone through them with go32's debugger. The problem
seems to be caused by a scrambled pointer-to-virtual-table. This reminds me of
a previous post on libg++ 2.5.3, which fixed a gcc code-gen bug with a hack in
streambuf.h; apparently ifstream v-tables were getting mangled incorrectly.
Sources for DJGPP libs seem to be derived from lg++2.5.0, iac definitely NOT
2.5.3, going by the differing changelog files in the libio directory.
Is there a version of the sources derived from libg++ 2.5.3? Does, or would
that fix the problems? I'm trying to apply dj diffs to the gnu libg++ 2.5.3.
Here are the sources. ouchout and ouchin crash in
[io]fstream::open(const char...), line close to end, while trying to call
virtual function seekoff() (due to ios::app or ios::ate). Unfortunately, the
pointer to vtable points to junk.
Seekout crashes in sputn(...) ?i think? called by ostream::write(...), when
sputn tries (so it appears) to find an address from a vtable, tho in this case
the scrambled pointer to vtable points to memory out of bounds, crashing.
Note that the first call to write() does not crash. If you use << instead of
write, seekout does not crash at all. You may want to use write for tables...
--------------------
// ouchout.cc
#include <fstream.h>
#include <stdio.h> // to use puts(). cout buffers don't clear before the crash.
void main()
{
char c='!';
puts("\n opening... \n\n\n"); // will print
ofstream ofile("qq.DAT", ios::app); // appending, try with an existing file
puts("\n writing... \n\n\n"); // we'll never get here
ofile << c;
}
---------------
// ouchin.cc
#include <fstream.h>
#include <stdio.h>
void main()
{
char c;
puts("\n opening... \n\n\n"); // ok
ifstream ifile("qq.DAT", ios::ate);
puts("\n reading... \n\n\n"); // we've died already
ifile >> c;
}
--------------
// seekout.cc
#include <fstream.h>
#include <stdio.h>
void main()
{
char c='!';
puts("\n opening... \n\n\n");
ofstream ofile("qq.DAT");
puts("\n seeking 0... \n\n\n");
ofile.seekp(0, ios::cur);
puts("\n writing at 0... \n\n\n");
ofile << c;
puts("\n seeking to end... \n\n\n");
ofile.seekp(0, ios::end); // ok so far, we can call
// virtual fn seekoff thru seekp
puts("\n writing from end... \n\n\n"); // this prints
ofile.write(&c,1);
puts("\n done! \n\n\n"); // we never get here
}
------------------------
-----------------------------------------------------------------------
Rishab Aiyer Ghosh "What is civilisation
rishab AT doe DOT ernet DOT in, rishab AT dxm DOT ernet DOT in but a ribonucleic
Voicemail +91 11 3760335; Vox/Fax/Data 6853410 hangover?"
H-34C Saket New Delhi 110017 INDIA
-----------------------------------------------------------------------
- Raw text -