[vtk-developers] stl container defect detection

Bill Lorensen bill.lorensen at gmail.com
Mon Jun 4 13:12:21 EDT 2012


Folks,

These flags:
 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
on g++ enable extra chekcing for stl containers. For example, they
will detect if an iterator is not valid, or if a container is
referenced outside its size. I have found several VTK and ITK bugs
using these (they work best for Debug builds).

It would be great if one of the nightly builds enabled these.

Here is a really subtle bug I just found in:

This line in ::GenerateParentChildLevelInformation()
parentsVec.assign(0, n);
should be
parentsVec.assign(n, 0);

Look here to see the subtle difference:
http://www.cplusplus.com/reference/stl/vector/assign/

With these flags, I received the following error and running with the
debugger was able to resolve:

3: Test command:
/home/lorensen/ProjectsGIT/VTKGerrit-linux/bin/vtkFiltersAMRCxxTests
"TestEnzoReader" "-D" "/home/lorensen/ProjectsGIT/VTKData"
3: Test timeout computed to be: 9.99988e+06
3: Filename: /home/lorensen/ProjectsGIT/VTKData/Data/AMR/Enzo/DD0010/moving7_0010.hierarchy
3: /usr/lib/gcc/i686-redhat-linux/4.4.5/../../../../include/c++/4.4.5/debug/vector:265:
3:     error: attempt to subscript container with out-of-bounds index
0, but
3:     container only holds 0 elements.
3:
3: Objects involved in the operation:
3: sequence "this" @ 0x0xbfbc2060 {
3:   type = NSt7__debug6vectorIjSaIjEEE;
3: }

Bill



More information about the vtk-developers mailing list