Skip to content

Commit bfb82fe

Browse files
committed
Cppcheck: Show single 'too many configurations' message if --enable=information hasn't been used and there are too many configurations.
1 parent 735069e commit bfb82fe

File tree

3 files changed

+58
-36
lines changed

3 files changed

+58
-36
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
195195
if (!settings._errorsOnly)
196196
reportUnmatchedSuppressions(settings.nomsg.getUnmatchedGlobalSuppressions());
197197

198+
cppCheck.tooManyConfigsError("",0U);
199+
198200
if (settings.isEnabled("missingInclude") && Preprocessor::missingIncludeFlag) {
199201
const std::list<ErrorLogger::ErrorMessage::FileLocation> callStack;
200202
ErrorLogger::ErrorMessage msg(callStack,

lib/cppcheck.cpp

Lines changed: 51 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static const char ExtraVersion[] = "";
4040
static TimerResults S_timerResults;
4141

4242
CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions)
43-
: _errorLogger(errorLogger), exitcode(0), _useGlobalSuppressions(useGlobalSuppressions)
43+
: _errorLogger(errorLogger), exitcode(0), _useGlobalSuppressions(useGlobalSuppressions), tooManyConfigs(false)
4444
{
4545
}
4646

@@ -171,46 +171,20 @@ unsigned int CppCheck::processFile(const std::string& filename)
171171
configurations.push_back(_settings.userDefines);
172172
}
173173

174-
if (_settings.isEnabled("information") && !_settings._force && configurations.size() > _settings._maxConfigs) {
175-
const std::string fixedpath = Path::toNativeSeparators(filename);
176-
ErrorLogger::ErrorMessage::FileLocation location;
177-
location.setfile(fixedpath);
178-
const std::list<ErrorLogger::ErrorMessage::FileLocation> loclist(1, location);
179-
std::ostringstream msg;
180-
msg << "Too many #ifdef configurations - cppcheck will only check " << _settings._maxConfigs << " of " << configurations.size() << ".\n"
181-
"The checking of the file will be interrupted because there are too many "
182-
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
183-
"by --force command line option or from GUI preferences. However that may "
184-
"increase the checking time.";
185-
ErrorLogger::ErrorMessage errmsg(loclist,
186-
Severity::information,
187-
msg.str(),
188-
"toomanyconfigs",
189-
false);
190-
191-
reportErr(errmsg);
174+
if (!_settings._force && configurations.size() > _settings._maxConfigs) {
175+
if (_settings.isEnabled("information")) {
176+
tooManyConfigsError(Path::toNativeSeparators(filename),configurations.size());
177+
} else {
178+
tooManyConfigs = true;
179+
}
192180
}
193181

194182
unsigned int checkCount = 0;
195183
for (std::list<std::string>::const_iterator it = configurations.begin(); it != configurations.end(); ++it) {
196184
// Check only a few configurations (default 12), after that bail out, unless --force
197185
// was used.
198-
if (_settings.isEnabled("information") && !_settings._force && checkCount >= _settings._maxConfigs) {
199-
200-
const std::string fixedpath = Path::toNativeSeparators(filename);
201-
ErrorLogger::ErrorMessage::FileLocation location;
202-
location.setfile(fixedpath);
203-
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
204-
loclist.push_back(location);
205-
ErrorLogger::ErrorMessage errmsg(loclist,
206-
Severity::information,
207-
"Interrupted checking because of too many #ifdef configurations.",
208-
"toomanyconfigs",
209-
false);
210-
211-
reportInfo(errmsg);
186+
if (!_settings._force && ++checkCount > _settings._maxConfigs)
212187
break;
213-
}
214188

215189
cfg = *it;
216190

@@ -234,8 +208,6 @@ unsigned int CppCheck::processFile(const std::string& filename)
234208
} else {
235209
checkFile(codeWithoutCfg + appendCode, filename.c_str());
236210
}
237-
238-
++checkCount;
239211
}
240212
} catch (const std::runtime_error &e) {
241213
// Exception was thrown when checking this file..
@@ -456,6 +428,46 @@ Settings &CppCheck::settings()
456428
return _settings;
457429
}
458430

431+
void CppCheck::tooManyConfigsError(const std::string &file, const std::size_t numberOfConfigurations)
432+
{
433+
if (!_settings.isEnabled("information") && !tooManyConfigs)
434+
return;
435+
436+
tooManyConfigs = false;
437+
438+
if (_settings.isEnabled("information") && file.empty())
439+
return;
440+
441+
std::list<ErrorLogger::ErrorMessage::FileLocation> loclist;
442+
if (!file.empty()) {
443+
ErrorLogger::ErrorMessage::FileLocation location;
444+
location.setfile(file);
445+
loclist.push_back(location);
446+
}
447+
448+
std::ostringstream msg;
449+
msg << "Too many #ifdef configurations - cppcheck only checks " << _settings._maxConfigs;
450+
if (numberOfConfigurations > _settings._maxConfigs)
451+
msg << " of " << numberOfConfigurations << " configurations. Use --force to check all configurations.\n";
452+
if (file.empty())
453+
msg << " configurations. Use --force to check all configurations. For more details, use --enable=information.\n";
454+
msg << "The checking of the file will be interrupted because there are too many "
455+
"#ifdef configurations. Checking of all #ifdef configurations can be forced "
456+
"by --force command line option or from GUI preferences. However that may "
457+
"increase the checking time.";
458+
if (file.empty())
459+
msg << " For more details, use --enable=information.";
460+
461+
462+
ErrorLogger::ErrorMessage errmsg(loclist,
463+
Severity::information,
464+
msg.str(),
465+
"toomanyconfigs",
466+
false);
467+
468+
reportErr(errmsg);
469+
}
470+
459471
//---------------------------------------------------------------------------
460472

461473
void CppCheck::reportErr(const ErrorLogger::ErrorMessage &msg)
@@ -534,6 +546,9 @@ void CppCheck::reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount
534546

535547
void CppCheck::getErrorMessages()
536548
{
549+
tooManyConfigs = true;
550+
tooManyConfigsError("",0U);
551+
537552
// call all "getErrorMessages" in all registered Check classes
538553
for (std::list<Check *>::iterator it = Check::instances().begin(); it != Check::instances().end(); ++it)
539554
(*it)->getErrorMessages(this, &_settings);

lib/cppcheck.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
131131
return _dependencies;
132132
}
133133

134+
void tooManyConfigsError(const std::string &file, const std::size_t numberOfConfigurations);
135+
134136
private:
135137

136138
/** @brief Process one file. */
@@ -189,6 +191,9 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
189191
unsigned int exitcode;
190192

191193
bool _useGlobalSuppressions;
194+
195+
/** Are there too many configs? */
196+
bool tooManyConfigs;
192197
};
193198

194199
/// @}

0 commit comments

Comments
 (0)