[Insight-developers] Anyone looked at cppcheck for static analysis of ITK?

kent williams norman-k-williams at uiowa.edu
Wed Sep 2 14:16:32 EDT 2009


I was running cppcheck over all our application source code, and while it
didn't find any actual errors, it does pick up some style issues worth
addressing in our code.

https://sourceforge.net/apps/mediawiki/cppcheck/index.php?title=Main_Page

As an exercise, I just ran it on the ITK Code tree, and it turns up stuff
that's more along the lines of cleanup rather than serious problems -- ITK
gets beat on pretty heavily after all!

[./Common/itkSize.h:46]: (style) The class 'Size' has no constructor
[./Common/itkFixedArray.h:146]: (style) Member variable not initialized in
the constructor 'FixedArray::operator'
[./Common/itkFixedArray.h:172]: (possible style) Member variable
'FixedArray::m_InternalArray' is not assigned a value in
'FixedArray::operator='
[./Common/itkFixedArray.h:172]: (possible style) Member variable
'FixedArray::operator' is not assigned a value in 'FixedArray::operator='
[./Common/itkFixedArray.h:172]: (possible style) Member variable
'FixedArray::ConstReverseIterator' is not assigned a value in
'FixedArray::operator='
[./Common/itkIndex.h:67]: (style) The class 'Index' has no constructor
[./Common/itkWeakPointer.h:104]: (possible style) Member variable
'WeakPointer<ProcessObject>::m_Pointer' is not assigned a value in
'WeakPointer<ProcessObject>::operator='
[./Common/itkCommand.cxx:22]: (style) Member variable not initialized in the
constructor 'CStyleCommand::m_ClientData'
[./Common/itkVariableLengthVector.h:137]: (possible style) Member variable
'VariableLengthVector::m_NumElements' is not assigned a value in
'VariableLengthVector::operator='
[./Common/itk_alloc.h:38]: (style) C-style pointer casting
[./Common/itk_alloc.h:40]: (style) C-style pointer casting

It also makes a lot of suggestions about limiting the scope of variables  --
in other words situations like this:

int tmp;
if(a < b)
{
tmp = a; a = b; b = tmp;
}
// no further use of tmp

Is this anything we want to think about using on a regular basis?

Oh and it doesn't use a comprehensive C++ parser, so ITK throws thousands of
false positives where it gets confused by complicated templates ;-) -- I
logged a bug with the cppcheck project.



More information about the Insight-developers mailing list