Changeset |
BUG: Fix uninitialized value in vtkMRMLColorTableNode.
Within vtkMRMLColorTableStorageNode::ReadDataInternal(), the method
vtkMRMLColorTableNode::SetColor() is called iteratively for all entries
to initialize the color names. In the same time, within SetColor(), the
method SetNamesFromColors() is also called.
This last call to SetNamesFromColors() is the problematic one. Indeed, it
attempts to initialize the color name for all entries while color values
are being set.
Since all color names are explicitly initialized, this commit removes
the call to "SetNamesFromColors()" from "SetColor()" function.
This commit fixes the error(s) reported below by valgrind memcheck tool.
Valgrind was used on Ubuntu 14.04 against a Debug build of Slicer. It was
exected doing the following:
(1) Start a terminal with the appropriate environment: ./Slicer --gnome-terminal
(2) Start Slicer using valgrind: valgrind --log-file=2015-07-16-Slicer-memcheck.txt --tool=memcheck --leak-check=yes ./bin/SlicerApp-real --disable-python --disable-cli-modules
(3) Exit Slicer and inspect valgrind log file
Valgrind error:
==17091== Conditional jump or move depends on uninitialised value(s)
==17091== at 0x2A67C4E7: __printf_fp (printf_fp.c:400)
==17091== by 0x2A67B792: vfprintf (vfprintf.c:1660)
==17091== by 0x2A69F578: vsnprintf (vsnprintf.c:119)
==17091== by 0x2A196E0F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==17091== by 0x2A19D263: std::ostreambuf_iterator<char, std::char_traits<char> > std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::_M_insert_float<double>(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, char, double) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==17091== by 0x2A19D54F: std::num_put<char, std::ostreambuf_iterator<char, std::char_traits<char> > >::do_put(std::ostreambuf_iterator<char, std::char_traits<char> >, std::ios_base&, char, double) const (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==17091== by 0x2A1A8AF4: std::ostream& std::ostream::_M_insert<double>(double) (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.19)
==17091== by 0xDB0E07B: vtkMRMLColorNode::SetNameFromColor(int) (vtkMRMLColorNode.cxx:312)
==17091== by 0xDB0DEBD: vtkMRMLColorNode::SetNamesFromColors() (vtkMRMLColorNode.cxx:295)
==17091== by 0xDB1CF37: vtkMRMLColorTableNode::SetColor(int, char const, double, double, double, double) (vtkMRMLColorTableNode.cxx:1301)
==17091== by 0xDB1F84D: vtkMRMLColorTableStorageNode::ReadDataInternal(vtkMRMLNode) (vtkMRMLColorTableStorageNode.cxx:146)
==17091== by 0xDCDE6D5: vtkMRMLStorageNode::ReadData(vtkMRMLNode, bool) (vtkMRMLStorageNode.cxx:1067)
==17091== Uninitialised value was created by a heap allocation
==17091== at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==17091== by 0x299257A3: vtkDataArrayTemplate<unsigned char>::Allocate(long long, long long) (vtkDataArrayTemplate.txx:137)
==17091== by 0x29928227: vtkDataArrayTemplate<unsigned char>::SetNumberOfValues(long long) (vtkDataArrayTemplate.txx:921)
==17091== by 0x29925A27: vtkDataArrayTemplate<unsigned char>::SetNumberOfTuples(long long) (vtkDataArrayTemplate.txx:355)
==17091== by 0x2986995A: vtkLookupTable::SetNumberOfTableValues(long long) (vtkLookupTable.cxx:1045)
==17091== by 0xDB1C6B5: vtkMRMLColorTableNode::SetNumberOfColors(int) (vtkMRMLColorTableNode.cxx:1241)
==17091== by 0xDB1F783: vtkMRMLColorTableStorageNode::ReadDataInternal(vtkMRMLNode) (vtkMRMLColorTableStorageNode.cxx:137)
==17091== by 0xDCDE6D5: vtkMRMLStorageNode::ReadData(vtkMRMLNode, bool) (vtkMRMLStorageNode.cxx:1067)
==17091== by 0xC9CD058: vtkMRMLColorLogic::CreateFileNode(char const) (vtkMRMLColorLogic.cxx:730)
==17091== by 0xC9CC104: vtkMRMLColorLogic::CreateFreeSurferFileNode(char const) (vtkMRMLColorLogic.cxx:593)
==17091== by 0xC9CE463: vtkMRMLColorLogic::AddFreeSurferFileNode(vtkMRMLFreeSurferProceduralColorNode) (vtkMRMLColorLogic.cxx:863)
==17091== by 0xC9CF282: vtkMRMLColorLogic::AddFreeSurferNodes() (vtkMRMLColorLogic.cxx:987)
git-svn-id: http://svn.slicer.org/Slicer4/trunk@24436 3bd1e089-480b-0410-8dfb-8563597acbee |