[ITK] Win64 Visual Studio 12 segfaults

Niels Dekker niels-xtk at xs4all.nl
Fri Jan 9 05:52:22 EST 2015


My colleague Floris Berendsen wrote:
> My colleague noticed a similar bug report to Visual Studio:
> https://connect.microsoft.com/VisualStudio/feedbackdetail/view/879286
> He wrote a minimal example to reproduce that issue, see the link.
> A segfault appears to occur in in IsInside(const Self & region) const
> of itkImageRegion.h as well, but we could not yet make a minimal example
> of that.

I think the following is a minimal example to reproduce the crash in
'IsInside' (from Modules\Core\Common\include\itkImageRegion.h). Please
check: store the code below into a CXX file, compile in Release mode
("/O2"), using the 64-bits version of Visual C++ 2013, and run!

  ////////////////////////////////////////////////////////////
  enum { ImageDimension = 4 };

  class SizeType {
    int m_data[ImageDimension];
  public:
    SizeType(): m_data() {}

    const int& operator[](unsigned i) const {
      return m_data[i];
    }
  };

  class RegionType {
    SizeType m_size;
  public:
    virtual const SizeType& GetSize() const {
      return m_size;
    }
  };

  int main() {
    const RegionType* const ptr = new RegionType();
    const RegionType& region = *ptr;
    typedef int IndexType[ImageDimension];
    IndexType beginCorner = { 0 };

    // The following is based on code from IsInside(const Self & region):

    IndexType endCorner;
    SizeType  size = region.GetSize();
    for (unsigned int i = 0; i < ImageDimension; i++)
    {
      endCorner[i] = beginCorner[i] + size[i] - 1;
    }

    delete ptr;
  }
  ////////////////////////////////////////////////////////////


Kind regards, Niels

--
Niels Dekker
Scientific programmer
LKEB, Leiden University Medical Center






More information about the Community mailing list