Skip to content

Commit

Permalink
Bailing out if too many (over 12) configurations found froma file. --…
Browse files Browse the repository at this point in the history
…force parameter added to prevent this from happening.
  • Loading branch information
aggro80 committed Dec 27, 2008
1 parent 3a39d18 commit 801f2c2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
15 changes: 15 additions & 0 deletions cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] );
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -161,8 +166,17 @@ void CppCheck::check()
preprocessor.preprocess(fin, fname, filedata, configurations );
}

int checkCount = 0;
for ( std::list<std::string>::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 );

Expand All @@ -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() )
Expand Down
9 changes: 9 additions & 0 deletions man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt"><option>--quiet</option></arg>
<arg choice="opt"><option>--style</option></arg>
<arg choice="opt"><option>--verbose</option></arg>
<arg choice="opt"><option>--force</option></arg>
<arg choice="opt"><option>file or path</option></arg>
<arg choice="plain"><option>...</option></arg>
</cmdsynopsis>
Expand Down Expand Up @@ -153,6 +154,14 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<para>More detailed error reports</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-f</option></term>
<term><option>--force</option></term>
<listitem>
<para>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.</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 id="author">
Expand Down
2 changes: 1 addition & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Settings::Settings()
_errorsOnly = false;
_checkFunctionUsage = false;
_verbose = false;
_force = false;
}

Settings::~Settings()
Expand Down
3 changes: 3 additions & 0 deletions settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class Settings
bool _errorsOnly;
bool _checkFunctionUsage;
bool _verbose;

/** Force checking t he files with "too many" configurations. */
bool _force;
};

#endif // SETTINGS_H

0 comments on commit 801f2c2

Please sign in to comment.