[Insight-users] Walking off the end of an array.

Mike Jackson mike.jackson at bluequartz.net
Sat Jun 6 09:33:48 EDT 2009


While running some code I kept getting some asserts from the HDF5
library that I am using when my program exited. Turns out that I had
something like this in my own code:



namespace R3D
{
  namespace Detail
  {
    const unsigned int Dimension = 2;
  }
}

typedef   unsigned char  PixelType;
typedef itk::Image<PixelType, R3D::Detail::Dimension>
 ImageType;
typedef itk::MeanSquaresImageToImageMetric<  ImageType, ImageType >
 MetricType;
MetricType::TransformParametersType metricParams(R3D::Detail::Dimension);


metricParams[0] = scale;
metricParams[1] = 0.0;
metricParams[2] = 0.0;
metricParams[3] = 0.0;

Turns out there are only 2 parameters for the metricParams array and
so I guess I was walking off the end of then array and assigning data
to memory locations in the HDF5 library area.

Turns out I was using the non-boundary checking version of those
calls. I should have been doing something like:
metricParams(2) = 0.0;
metricParams.put(2, 0.0);

So I tried those fully expecting an assert to happen by my code
completes successfully now. I compiled ITK in debug mode along with my
code. Is there something else that needs to be done in order to enable
these asserts or boundary checking? I am still new to ITK and so I
would like to have the safety net.

Thanks
Mike Jackson


More information about the Insight-users mailing list