From 801f2c246d302d09b059d723221e2e8af903fc4f Mon Sep 17 00:00:00 2001 From: Reijo Tomperi Date: Sat, 27 Dec 2008 07:52:07 +0000 Subject: [PATCH] Bailing out if too many (over 12) configurations found froma file. --force parameter added to prevent this from happening. --- cppcheck.cpp | 15 +++++++++++++++ man/cppcheck.1.xml | 9 +++++++++ readme.txt | 2 +- settings.cpp | 1 + settings.h | 3 +++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cppcheck.cpp b/cppcheck.cpp index b99223533..9d41d21c4 100644 --- a/cppcheck.cpp +++ b/cppcheck.cpp @@ -88,6 +88,10 @@ std::string CppCheck::parseFromArgs( int argc, const char* const argv[] ) else if (strcmp(argv[i],"-v")==0 || strcmp(argv[i],"--verbose")==0) _settings._verbose = true; + // Force checking of files that have "too many" configurations + else if (strcmp(argv[i],"-f")==0 || strcmp(argv[i],"--force")==0) + _settings._force = true; + else pathnames.push_back( argv[i] ); } @@ -118,6 +122,7 @@ std::string CppCheck::parseFromArgs( int argc, const char* const argv[] ) " -q, --quiet Only print error messages\n" " -s, --style Check coding style\n" " -v, --verbose More detailed error reports\n" + " -f, --force Force checking on files that have \"too many\" configurations\n" "\n" "Example usage:\n" " # Recursively check ../myproject/ and print only most fatal errors:\n" @@ -161,8 +166,17 @@ void CppCheck::check() preprocessor.preprocess(fin, fname, filedata, configurations ); } + int checkCount = 0; for ( std::list::const_iterator it = configurations.begin(); it != configurations.end(); ++it ) { + // Check only 12 first configurations, after that bail out, unless --force + // was used. + if( !_settings._force && checkCount > 11 ) + { + _errorLogger->reportErr( std::string( "Bailing out from checking " ) + fname + ": Too many configurations. Recheck this file with --force if you want to check them all." ); + break; + } + cfg = *it; std::string codeWithoutCfg = Preprocessor::getcode( filedata, *it ); @@ -171,6 +185,7 @@ void CppCheck::check() _errorLogger->reportOut( std::string( "Checking " ) + fname + ": "+cfg+std::string( "..." ) ); checkFile( codeWithoutCfg, _filenames[c].c_str()); + checkCount++; } if ( _settings._errorsOnly == false && _errout.str().empty() ) diff --git a/man/cppcheck.1.xml b/man/cppcheck.1.xml index 4eaf75d4d..ba9309025 100644 --- a/man/cppcheck.1.xml +++ b/man/cppcheck.1.xml @@ -106,6 +106,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ + @@ -153,6 +154,14 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ More detailed error reports + + + + + Force checking of files that have a lot of configurations. Error is printed if such a file is found so there is no reason to use this by +default. + + diff --git a/readme.txt b/readme.txt index fabcc9ecb..4e0ca66a2 100644 --- a/readme.txt +++ b/readme.txt @@ -22,7 +22,7 @@ Compiling Usage The syntax is: - cppcheck [--all] [--quiet] [--style] [file or path] [file or path] + cppcheck [--all] [--quiet] [--style] [--verbose] [--force] [file or path] [file or path] The error messages will be printed to stderr. diff --git a/settings.cpp b/settings.cpp index 76451181c..ba0bc9a2a 100644 --- a/settings.cpp +++ b/settings.cpp @@ -26,6 +26,7 @@ Settings::Settings() _errorsOnly = false; _checkFunctionUsage = false; _verbose = false; + _force = false; } Settings::~Settings() diff --git a/settings.h b/settings.h index e3f94ca49..4ecd8afbf 100644 --- a/settings.h +++ b/settings.h @@ -36,6 +36,9 @@ public: bool _errorsOnly; bool _checkFunctionUsage; bool _verbose; + + /** Force checking t he files with "too many" configurations. */ + bool _force; }; #endif // SETTINGS_H