Permalink
Browse files

COMP: Fix all valid cppcheck warnings in ITK (last patch)

  Previously five patches were sent about fixing cppcheck warnings in
  ITK/Module directory.

  At the current patch, all other valid remained cppcheck warnings in
  the ITK directory are fixed. All the remained valid warnings were from
  Example/ directory.

  One example of invalid warnings are those that are about unused
  functions. This functions are not used in static analysis, but the are
  used by users in real applications.

  The fixed issues are generally about the following topics:

  1) In definition of class A:
    the 'A::operator=' should return 'A &'. However, they would return
    viod.

  2) Prefix ++/-- operators are preferred for non-primitive types.

  3) Initialization to assignment is preferred.

  4) If possible, variables are passed by reference.(This warning mostly
    happens about Exception catching).

  5) Emptiness of variables are checked efficiently using the empty()
  function.

  6) Unused variables are removed.

  All the ITK tests are passed after the above changes.

Change-Id: I00e4804b4e26dbc2e709d17a82279713be36f307
  • Loading branch information...
1 parent 0545777 commit a3793658d265e09de0ca19d407637c74ad6aceb3 @aghayoor aghayoor committed with Kent Williams Mar 7, 2013
@@ -60,7 +60,8 @@
//
// Software Guide : EndLatex
-
+namespace itk
+{
// Software Guide : BeginCodeSnippet
class VectorPixelAccessor
{
@@ -70,9 +71,10 @@ class VectorPixelAccessor
VectorPixelAccessor() : m_Index(0) {}
- void operator=( const VectorPixelAccessor & vpa )
+ VectorPixelAccessor & operator=( const VectorPixelAccessor & vpa )
{
m_Index = vpa.m_Index;
+ return *this;
}
ExternalType Get( const InternalType & input ) const
{
@@ -87,7 +89,7 @@ class VectorPixelAccessor
unsigned int m_Index;
};
// Software Guide : EndCodeSnippet
-
+}
// Software Guide : BeginLatex
//
@@ -150,7 +152,7 @@ int main( int argc, char *argv[] )
// Software Guide : BeginCodeSnippet
typedef itk::ImageAdaptor< VectorImageType,
- VectorPixelAccessor > ImageAdaptorType;
+ itk::VectorPixelAccessor > ImageAdaptorType;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
// Software Guide : EndCodeSnippet
@@ -167,7 +169,7 @@ int main( int argc, char *argv[] )
// Software Guide : BeginCodeSnippet
- VectorPixelAccessor accessor;
+ itk::VectorPixelAccessor accessor;
accessor.SetIndex( atoi( argv[3] ) );
adaptor->SetPixelAccessor( accessor );
// Software Guide : EndCodeSnippet
@@ -56,7 +56,8 @@
//
// Software Guide : EndLatex
-
+namespace itk
+{
// Software Guide : BeginCodeSnippet
class ThresholdingPixelAccessor
{
@@ -75,14 +76,17 @@ class ThresholdingPixelAccessor
m_Threshold = threshold;
}
- void operator=( const ThresholdingPixelAccessor & vpa )
+ ThresholdingPixelAccessor & operator=( const ThresholdingPixelAccessor & vpa )
{
m_Threshold = vpa.m_Threshold;
+ return *this;
}
private:
InternalType m_Threshold;
};
+}
+
// Software Guide : EndCodeSnippet
@@ -123,7 +127,7 @@ int main( int argc, char *argv[] )
// Software Guide : BeginCodeSnippet
- typedef ThresholdingPixelAccessor::InternalType PixelType;
+ typedef itk::ThresholdingPixelAccessor::InternalType PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
// Software Guide : EndCodeSnippet
@@ -140,7 +144,7 @@ int main( int argc, char *argv[] )
// Software Guide : BeginCodeSnippet
typedef itk::ImageAdaptor< ImageType,
- ThresholdingPixelAccessor > ImageAdaptorType;
+ itk::ThresholdingPixelAccessor > ImageAdaptorType;
ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
// Software Guide : EndCodeSnippet
@@ -156,7 +160,7 @@ int main( int argc, char *argv[] )
// Software Guide : BeginCodeSnippet
- ThresholdingPixelAccessor accessor;
+ itk::ThresholdingPixelAccessor accessor;
accessor.SetThreshold( atoi( argv[3] ) );
adaptor->SetPixelAccessor( accessor );
// Software Guide : EndCodeSnippet
@@ -283,7 +283,7 @@ int main( int argc, char* argv[] )
{
writer->Update();
}
- catch ( itk::ExceptionObject e )
+ catch ( itk::ExceptionObject & e )
{
std::cerr << "Error: " << e << std::endl;
}
@@ -255,7 +255,7 @@ int main( int argc, char * argv[] )
{
offsetWriter->Update();
}
- catch( itk::ExceptionObject exp )
+ catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
@@ -167,8 +167,6 @@ int main( int argc, char * argv[] )
InputPixelType lowerThreshold = 0;
InputPixelType upperThreshold;
- std::string format = argv[2];
-
char outputFilename[1000];
outputFile = outputFileBase + "%03d.";
outputFile += argv[3]; // filename extension
@@ -133,7 +133,7 @@ int main( int argc, char * argv[] )
{
writer->Update();
}
- catch( itk::ExceptionObject exp )
+ catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
@@ -156,7 +156,7 @@ int main( int argc, char * argv[] )
{
voronoiWriter->Update();
}
- catch( itk::ExceptionObject exp )
+ catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
@@ -182,7 +182,7 @@ int main( int argc, char * argv[] )
{
offsetWriter->Update();
}
- catch( itk::ExceptionObject exp )
+ catch( itk::ExceptionObject & exp )
{
std::cerr << "Exception caught !" << std::endl;
std::cerr << exp << std::endl;
@@ -208,7 +208,7 @@ int main( int argc, char *argv[] )
{
fieldWriter->Update();
}
- catch ( itk::ExceptionObject e )
+ catch ( itk::ExceptionObject & e )
{
e.Print( std::cerr );
}
@@ -201,7 +201,7 @@ int main( int argc, char *argv[] )
{
fieldWriter->Update();
}
- catch ( itk::ExceptionObject e )
+ catch ( itk::ExceptionObject & e )
{
e.Print( std::cerr );
}
@@ -398,8 +398,8 @@ int main( int argc, char *argv[] )
FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
MovingImageReaderType::Pointer movingImageReader = MovingImageReaderType::New();
- fixedImageReader->SetFileName( argv[1] );
- movingImageReader->SetFileName( argv[2] );
+ fixedImageReader->SetFileName( fixedImageFile );
+ movingImageReader->SetFileName( movingImageFile );
// Software Guide : BeginLatex
@@ -644,7 +644,7 @@ int main( int argc, char *argv[] )
CastFilterType::Pointer caster = CastFilterType::New();
- writer->SetFileName( argv[3] );
+ writer->SetFileName( outImagefile );
caster->SetInput( resample->GetOutput() );
@@ -91,7 +91,7 @@ int main( int , char *[] )
v[k] = k;
}
p.SetTensorMatrix(v);
- delete v;
+ delete [] v;
p.SetColor(1,0,0,1);
list.push_back(p);
}
@@ -71,7 +71,7 @@ class PyCommand : public Command
~PyCommand();
void PyExecute();
PyCommand(const Self&); // Not implemented.
- void operator=(const Self&); // Not implemented.
+ PyCommand & operator=(const Self&); // Not implemented.
private:
PyObject *m_Object;
@@ -61,7 +61,7 @@ class TclCommand : public Command
TclCommand();
~TclCommand() {}
TclCommand(const Self&); // Not implemented.
- void operator=(const Self&); // Not implemented.
+ TclCommand & operator=(const Self&); // Not implemented.
void TclExecute() const;

0 comments on commit a379365

Please sign in to comment.