This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
RE: c++/1843
- To: nobody at gcc dot gnu dot org
- Subject: RE: c++/1843
- From: "Steven Belbin" <steven dot belbin at sympatico dot ca>
- Date: 19 Feb 2001 01:16:01 -0000
- Cc: gcc-prs at gcc dot gnu dot org,
- Reply-To: "Steven Belbin" <steven dot belbin at sympatico dot ca>
The following reply was made to PR c++/1843; it has been noted by GNATS.
From: "Steven Belbin" <steven.belbin@sympatico.ca>
To: <rodrigc@mediaone.net>
Cc:
Subject: RE: c++/1843
Date: Sun, 18 Feb 2001 19:20:52 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_0000_01C099DF.E883C380
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: 7bit
Hi Craig,
I included a sample with the GNAT bug report, regardless here is a sample
that provokes a segmentation fault.
============= gcc_bug_1843.cpp =======================
#include <string.h>
#include <iostream.h>
char * StringAllocate( const char * text )
{
int size = ( text ) ? strlen( text ) : 0;
char * result = new char [ size + 1 ];
if ( text )
strncpy( result , text , size );
result[ size ] = '\0';
return result;
}
class error
{
private:
char * m_text;
public:
error() :
m_text( StringAllocate( NULL ) )
{}
error( const char * text ) :
m_text( StringAllocate( text ) )
{}
error( const error & other ) :
m_text( StringAllocate( other.m_text ) )
{}
virtual ~error()
{ delete [] m_text; }
const char * text() const
{ return m_text; }
};
ostream & operator <<( ostream & output , const error & err )
{
return output << err.text();
}
class fatal_error :
virtual public error
{
public:
fatal_error()
{}
fatal_error( const char * text ) :
error( text )
{}
virtual ~fatal_error()
{}
};
int main( int argc , char * argv[] )
{
try
{
throw fatal_error( "Throwing a fatal error." );
}
catch( const error & err )
{
cerr << endl << err << endl;
}
return 0;
}
============================================================
As you can see it is straight forward example.
Notes:
I have even tried using the C++ string class for the error::m_text variable
(without the delete [] m_text in the destructor) and a segmentation fault
still occurs.
When error is not virtual within the fatal_error the segmentation fault does
not occur.
The case that triggered this issue is more complex than the sample, in which
virtual inherence is required of a class that can be thrown as an exception.
P.S.
Please, try not to reply with the typical doctor-patient shoulder reponse.
[ Patient ] - Doctor, my shoulder hurts when I move it.
[ Doctor ] - Then don't move it.
-----Original Message-----
From: rodrigc@mediaone.net [mailto:rodrigc@mediaone.net]
Sent: February 17, 2001 03:53 PM
To: gcc-gnats@gcc.gnu.org; xavier.oriol@delta-tek.com;
nobody@gcc.gnu.org; steven.belbin@delta-tek.com; rodrigc@mediaone.net
Subject: Re: c++/1843
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=1843&database=gcc
There is no attached file associated with this report.
Can you submit a test case?
--
Craig Rodrigues
http://www.gis.net/~craigr
rodrigc@mediaone.net
------=_NextPart_000_0000_01C099DF.E883C380
Content-Type: application/octet-stream;
name="gcc_exception_bug.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="gcc_exception_bug.cpp"
#include <string.h>
#include <iostream.h>
char * StringAllocate( const char * text )
{
int size = ( text ) ? strlen( text ) : 0;
char * result = new char [ size + 1 ];
if ( text )
strncpy( result , text , size );
result[ size ] = '\0';
return result;
}
class error
{
private:
char * m_text;
public:
error() :
m_text( StringAllocate( NULL ) )
{}
error( const char * text ) :
m_text( StringAllocate( text ) )
{}
error( const error & other ) :
m_text( StringAllocate( other.m_text ) )
{}
virtual ~error()
{ delete [] m_text; }
const char * text() const
{ return m_text; }
};
ostream & operator <<( ostream & output , const error & err )
{
return output << err.text();
}
class fatal_error :
virtual public error
{
public:
fatal_error()
{}
fatal_error( const char * text ) :
error( text )
{}
virtual ~fatal_error()
{}
};
int main( int argc , char * argv[] )
{
try
{
throw fatal_error( "Throwing a fatal error." );
}
catch( const error & err )
{
cerr << endl << err << endl;
}
return 0;
}
------=_NextPart_000_0000_01C099DF.E883C380--