|
Prev: FREE Tutorials on HTML XHTML CSS JavaScript XML XSL ASP SQL ADO VBScript, SAP - ABAP and more...
Next: Check whether a file handle is open
From: Niels Dekker - no return address on 2 Jun 2008 08:41 The assignment operator of the VC7.1 SP1 edition of std::exception appears to have a major bug. When it is called on an object of a class derived from std::exception, it might corrupt the virtual table of the object. When it does, a subsequent virtual function call causes a crash. For example: ////////////////////////////////////////////////// #include <exception> class MyException : public std::exception { public: int NonVirtualFun() { return VirtualFun(); } virtual int VirtualFun() { return 0; } }; int main() { MyException a, b; a = b; // Internally calls std::exception::operator=. return a.NonVirtualFun(); // MSVC 2003 crash! } ////////////////////////////////////////////////// Is this a known issue? Fortunately I could not reproduce the crash on later versions of Visual C++. So is it fixed? I couldn't find a bug report on the issue. Originally I thought that it had to do with the bug reported by Jouni Kiviniemi at https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=328570 "Memory leak on std::exception assignment operator", but that one doesn't mention any crash. Kind regards, -- Niels Dekker http://www.xs4all.nl/~nd/dekkerware Scientific programmer at LKEB, Leiden University Medical Center |