MantisBT - ITK
View Issue Details
0002485ITKpublic2005-11-14 11:302007-09-21 16:33
 
user390 
normalmajoralways
closedfixed 
 
 
0002485: PointIdsEnd() of itk::PolygonCell crashes in Visual Studio 2005
The "return &*(m_PointIds.end())" construction of the PointIdsEnd() method in itk::PolygonCell causes applications built using Visual Studio 2005 to crash.

The Debug version of applications calling this method causes error "vector iterator not dereferencable" in "operator*()".

It seems like Microsoft has implemented the std::vector class differently, and dereferencing the past end iterator is no longer possible.

One possible solution is to change the return expression into:

return &(m_PointIds[GetNumberOfPoints()-1])+1;

Of course this will cause problems if the polygon cell is empty.
No tags attached.
Issue History
2007-09-21 16:33Luis IbanezStatusresolved => closed
2007-09-21 16:33Luis IbanezNote Added: 0009220

Notes
(0003289)
Lydia Ng   
2005-11-22 11:21   

(0003342)
user390   
2005-11-30 14:17   
Thanks for pointing this out. Its fixed.

http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkPolygonCell.txx?root=Insight&r1=text&tr1=1.30&r2=text&tr2=1.29&diff_format=h [^]

Notes:

As you mentioned VS8 checks if an iterator is dereferencible prior to derefencing it.. (probably in one of the debug modes..)

#if _HAS_ITERATOR_DEBUGGING
        if (this->_Mycont == 0
            || _Myptr < ((_Myvec *)this->_Mycont)->_Myfirst
            || ((_Myvec *)this->_Mycont)->_Mylast <= _Myptr)
            {
            _DEBUG_ERROR("vector iterator not dereferencable");
            _SCL_SECURE_OUT_OF_RANGE;
            }
 #else
....


Prior to copying the points from another cell, the Polygon cell now checks if the other cell had any points at all, avoiding bogus dereferences. The usual begin and end methods are not checked however for efficieny. This should fix the bugs.
(0007841)
Bill Lorensen   
2007-06-08 14:40   
I'm not sure this was fixed in 2.2. It is now corrected in CVS Head (post 3.2). The fix is the one suggested by the reporter.
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkPolygonCell.txx?root=Insight&r1=1.30&r2=1.31 [^]
(0009220)
Luis Ibanez   
2007-09-21 16:33   
changing status from 'resolved' to 'closed'

The issue was already fixed in the CVS trunk.