diff --git a/CheckBufferOverrun.cpp b/CheckBufferOverrun.cpp index d28d791f5..20950e7a6 100644 --- a/CheckBufferOverrun.cpp +++ b/CheckBufferOverrun.cpp @@ -35,7 +35,8 @@ // _callStack used when parsing into subfunctions. -CheckBufferOverrunClass::CheckBufferOverrunClass( const Tokenizer *tokenizer, ErrorLogger *errorLogger ) +CheckBufferOverrunClass::CheckBufferOverrunClass( const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger ) + : _settings(settings) { _tokenizer = tokenizer; _errorLogger = errorLogger; @@ -220,6 +221,10 @@ void CheckBufferOverrunClass::CheckBufferOverrun_CheckScope( const TOKEN *tok, c { // Don't make recursive checking.. if (std::find(_callStack.begin(), _callStack.end(), tok) != _callStack.end()) + continue; + + // Only perform this checking if showAll setting is enabled.. + if ( ! _settings._showAll ) continue; unsigned int parlevel = 0, par = 0; diff --git a/CheckBufferOverrun.h b/CheckBufferOverrun.h index a891f9e9f..95948fd31 100644 --- a/CheckBufferOverrun.h +++ b/CheckBufferOverrun.h @@ -28,7 +28,7 @@ class CheckBufferOverrunClass { public: - CheckBufferOverrunClass( const Tokenizer *tokenizer, ErrorLogger *errorLogger ); + CheckBufferOverrunClass( const Tokenizer *tokenizer, const Settings &settings, ErrorLogger *errorLogger ); ~CheckBufferOverrunClass(); // Buffer overrun.. @@ -43,7 +43,8 @@ private: void CheckBufferOverrun_CheckScope( const TOKEN *tok, const char *varname[], const int size, const int total_size ); void ReportError(const TOKEN *tok, const char errmsg[]); - const Tokenizer *_tokenizer; + const Tokenizer *_tokenizer; + const Settings _settings; ErrorLogger *_errorLogger; std::list _callStack; }; diff --git a/cppcheck.cpp b/cppcheck.cpp index ed93a5845..722c20841 100644 --- a/cppcheck.cpp +++ b/cppcheck.cpp @@ -244,7 +244,7 @@ void CppCheck::checkFile(const std::string &code, const char FileName[]) checkMemoryLeak.CheckMemoryLeak(); // Buffer overruns.. - CheckBufferOverrunClass checkBufferOverrun( &_tokenizer, this ); + CheckBufferOverrunClass checkBufferOverrun( &_tokenizer, _settings, this ); checkBufferOverrun.CheckBufferOverrun(); // Check that all class constructors are ok. diff --git a/testbufferoverrun.cpp b/testbufferoverrun.cpp index ac4a36d3b..5c297c5ca 100644 --- a/testbufferoverrun.cpp +++ b/testbufferoverrun.cpp @@ -50,8 +50,10 @@ private: // Clear the error buffer.. errout.str(""); - // Check for buffer overruns.. - CheckBufferOverrunClass checkBufferOverrun( &tokenizer, this ); + // Check for buffer overruns.. + Settings settings; + settings._showAll = true; + CheckBufferOverrunClass checkBufferOverrun( &tokenizer, settings, this ); checkBufferOverrun.CheckBufferOverrun(); }