From 5e27b6b62f174363fcd17e06fbcc8885ab34e9c2 Mon Sep 17 00:00:00 2001 From: Giovanni Bussi <giovanni.bussi@gmail.com> Date: Mon, 25 May 2015 13:04:16 -0500 Subject: [PATCH] Fixed cppcheck issues and added suppress comment --- src/core/CLTool.cpp | 4 +++- src/tools/Communicator.cpp | 8 ++++++++ src/tools/Matrix.h | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/CLTool.cpp b/src/core/CLTool.cpp index 4a3b48c7b..ed1b17830 100644 --- a/src/core/CLTool.cpp +++ b/src/core/CLTool.cpp @@ -171,6 +171,8 @@ bool CLTool::readInputFile( int argc, char**argv, FILE* in, FILE*out ){ } } + plumed_assert(mystdin); + char buffer[256]; std::string line; line.resize(256); while(fgets(buffer,256,mystdin)){ line=buffer; @@ -193,7 +195,7 @@ bool CLTool::readInputFile( int argc, char**argv, FILE* in, FILE*out ){ fprintf(out,"Usage: %s < inputFile \n", name.c_str() ); fprintf(out,"inputFile should contain one directive per line. The directives should come from amongst the following\n\n"); keywords.print( out ); - if(mystdin) fclose(mystdin); + fclose(mystdin); return false; } } diff --git a/src/tools/Communicator.cpp b/src/tools/Communicator.cpp index f5ba71f94..135631880 100644 --- a/src/tools/Communicator.cpp +++ b/src/tools/Communicator.cpp @@ -34,12 +34,20 @@ Communicator::Communicator() { } +// cppcheck complains about this: +// Member variable 'Communicator::communicator' is not initialized in the constructor +// this is a false positive so I suppress it +// cppcheck-suppress uninitMemberVar Communicator::Communicator(const Communicator&pc){ Set_comm(pc.communicator); } Communicator::Status Communicator::StatusIgnore; +// cppcheck complains about this: +// Member variable 'Communicator::communicator' is not assigned a value in 'Communicator::operator=' +// this is a false positive so I suppress it +// cppcheck-suppress operatorEqVarError Communicator& Communicator::operator=(const Communicator&pc){ if (this != &pc){ Set_comm(pc.communicator); diff --git a/src/tools/Matrix.h b/src/tools/Matrix.h index faf2004e5..9f5317246 100644 --- a/src/tools/Matrix.h +++ b/src/tools/Matrix.h @@ -339,6 +339,10 @@ template <typename T> void cholesky( const Matrix<T>& A, Matrix<T>& B ){ Matrix<T> L(A.rw ,A.cl); L=0.; std::vector<T> D(A.rw,0.); for(unsigned i=0; i<A.rw; ++i){ +// The following line triggers a warning in cppcheck, +// perhaps because of the conversion of "1" to an unspecified type +// I suppress it explicitly +// cppcheck-suppress compareBoolExpressionWithInt L(i,i)=static_cast<T>( 1 ); for (unsigned j=0; j<i; ++j){ L(i,j)=A(i,j); -- GitLab