Mail Archives: djgpp/1996/04/06/07:13:42
Xref: | news2.mv.net comp.os.msdos.djgpp:2479
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Bug in libiostream.a (V.2.7.1)
|
Message-ID: | <3163BB5B.4C28@Mathematik.tu-chemnitz.de>
|
From: | Robert Hoehne <Robert DOT Hoehne AT Mathematik DOT tu-chemnitz DOT de>
|
Date: | Thu, 04 Apr 1996 14:06:51 +0200
|
Organization: | TU Chemnitz-Zwickau
|
NNTP-Posting-Host: | tantalus-e.hrz.tu-chemnitz.de
|
Mime-Version: | 1.0
|
Lines: | 106
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
This is a multi-part message in MIME format.
--------------38B154964828
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi everybody,
I have found a bug in this library. I sent this report also to
bug-lib-g++@prep.ai.mit.edu, but I think for all of you, who use
this library it is also of interest. I have included in this post
a sample source file, which shows the bug and it is commented.
Robert
--
*****************************************************************
* Robert Hoehne, Fakultaet fuer Mathematik, TU-Chemnitz-Zwickau *
* Post: Am Berg 3, D-09573 Dittmannsdorf *
* e-Mail: Robert DOT Hoehne AT Mathematik DOT TU-Chemnitz DOT DE *
* WWW: http://www.tu-chemnitz.de/~rho *
*****************************************************************
--------------38B154964828
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="test.cc"
#include <iostream.h>
#include <stdio.h>
/*
this file demonstrates the bug in the GNU iostream library
if there is a class, which has multiple base classes and the
class streambuf is not the first basclass, then the calls to
the overwritten functions of streambuf are called with an incorrect
value of the this-variable.
compile this program with
gcc -o test test.cc -liostream
and the program terminates with the error message in the function
Filebuf::overflow
This bug comes with all functions, which are called over the JUMP...
-macros from the library, which are defined in libioP.h
*/
class dummyclass
{
public:
void init() {}
};
static void * THIS; /* holds the this-pointer of the FileBuf class */
class Filebuf : public dummyclass, public streambuf {
FILE *file;
public:
Filebuf (FILE *f) {
file = f;
THIS = this;
}
virtual int overflow (int ch);
virtual streamsize xsputn (char* text, streamsize n);
};
int Filebuf::overflow (int ch)
{
if (this != THIS)
{
fprintf(stderr,"value of `this' isn't correct. Is : %08X must be : %08X\n",
(int)this,(int)THIS);
exit(-1);
}
/* if the above check is not done, the program tries to compute the
this pointer for the call of xsputn from an invalid this pointer. It
points in this function, if it is called from the iostream library,
to the streambuf baseclass of Filebuf and not to Filebuf */
if (ch != EOF)
{
char c[2];
c[0] = ch;
xsputn(c,1);
return 1;
}
return 0;
}
streamsize Filebuf::xsputn(char *text,streamsize n)
{
fwrite(text,1,n,file);
}
int main (int argc, char**argv)
{
Filebuf fbuf(stdout);
ostream fstr(&fbuf);
fstr << "Hello world!\n";
}
--------------38B154964828--
- Raw text -