[Insight-developers] ExceptionObject assignment crash on MSVC
Luis Ibanez
luis.ibanez at kitware.com
Fri May 30 19:27:47 EDT 2008
Hi Niels,
Here is what I have found so far:
In Visual Studio 7.1, the superclass of itk::ExceptionObject,
the std::exception, is not initializing its "what" component.
When running in Debug mode, it crashes in the expressions
std::cout << E << std::endl;
the "what" component of std::exception is only set at construction
time, and we are not explicitly setting it up.
This can be fixed in the three constructors of itk::ExceptionObject
with the following changes:
-------------------------------------------------------------
$ cvs -q diff
Index: itkExceptionObject.cxx
===================================================================
RCS file: /cvsroot/Insight/Insight/Code/Common/itkExceptionObject.cxx,v
retrieving revision 1.14
diff -r1.14 itkExceptionObject.cxx
134c134
< ExceptionObject::ExceptionObject()
---
> ExceptionObject::ExceptionObject():Superclass("")
144c144
< :
---
> :Superclass(desc),
154c154
< :
---
> :Superclass(desc.c_str()),
161c161
< Superclass(orig),
---
> Superclass(orig.what()),
------------------------------------------------------
This bring us up to the next problem:
Apparently in the triple assignment:
E = F = G;
Something goes wrong in the reference counting of E,F,G
is done improperly, and when we get to the next line:
std::cout << F << std::endl;
it attempts to use an invalid object for invoking
its Print() method.
This requires a closer look....
...and still is unclear why is that it is a
problem only in VS71 (and maybe the same in VS6 ?).
Luis
------------------
Niels Dekker wrote:
> Luis Ibanez wrote:
>
>> Removing the lines from the test may not be the right way to
>> address the problem. That will just give us a deceptively
>> green Dashboard and a false sense of security.
>
>
> Sorry, typo, I meant to say: feel free to remove those two lines of code
> from itkExceptionObject.cxx:
>
> // Assign its superclass:
> static_cast<Superclass &>(*this) = orig;
>
> I didn't mean to suggest changing the test.
>
>
>> The memory leak reported for std::exception shouldn't result
>> in a crash, isn't it? ... it should just ... leak memory.
>
>
> Good point. But still, the bug report on the Microsoft website gives me
> a bad feeling about their implementation of std::exception::operator=.
> Hope you can prove me wrong.
>
>> I'll try running this in Debug mode...
>
>
> Please do. Note that the previous version of itk::ExceptionObject
> (before I did anything to the class) didn't call
> std::exception::operator=. And it didn't crash!
>
>
> Now I'm really going home! Sorry to leave you with the crash (at least
> for today).
>
>
> Kind regards,
>
> Niels
>
>
>
>
>
>
More information about the Insight-developers
mailing list