@@ -1014,16 +1014,33 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1014
1014
1015
1015
// Get configurations..
1016
1016
std::set<std::string> configurations;
1017
- if ((mSettings .checkAllConfigurations && mSettings .userDefines .empty ()) || mSettings .force ) {
1018
- Timer::run (" Preprocessor::getConfigs" , mSettings .showtime , &s_timerResults, [&]() {
1017
+ Timer::run (" Preprocessor::getConfigs" , mSettings .showtime , &s_timerResults, [&]() {
1019
1018
configurations = preprocessor.getConfigs (tokens1);
1020
- });
1019
+ });
1020
+
1021
+ std::list<std::string> configs_total;
1022
+ if (!mSettings .userDefines .empty ()) {
1023
+ configs_total.push_back (mSettings .userDefines );
1024
+ }
1025
+
1026
+ int max_config_tmp;
1027
+ if (mSettings .force ) {
1028
+ max_config_tmp = configurations.size ();
1021
1029
} else {
1022
- configurations.insert (mSettings .userDefines );
1030
+ if (mSettings .preprocessOnly ) {
1031
+ max_config_tmp = 1 ;
1032
+ } else {
1033
+ max_config_tmp = mSettings .maxConfigs ;
1034
+ }
1035
+ max_config_tmp = max_config_tmp - configs_total.size ();
1036
+ }
1037
+
1038
+ for (auto it = configurations.begin (); it != configurations.end () && max_config_tmp > 0 ; ++it, max_config_tmp--) {
1039
+ configs_total.push_back (*it);
1023
1040
}
1024
1041
1025
1042
if (mSettings .checkConfiguration ) {
1026
- for (const std::string &config : configurations )
1043
+ for (const std::string &config : configs_total )
1027
1044
(void )preprocessor.getcode (tokens1, config, files, true );
1028
1045
1029
1046
if (analyzerInformation)
@@ -1046,10 +1063,10 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1046
1063
executeRules (" define" , tokenlist);
1047
1064
}
1048
1065
#endif
1049
-
1050
- if (!mSettings .force && configurations. size () > mSettings .maxConfigs ) {
1066
+ int max_total = configurations. size () + mSettings . userDefines . empty () ? 0 : 1 ;
1067
+ if (!mSettings .force && max_total > mSettings .maxConfigs ) {
1051
1068
if (mSettings .severity .isEnabled (Severity::information)) {
1052
- tooManyConfigsError (Path::toNativeSeparators (file.spath ()),configurations. size () );
1069
+ tooManyConfigsError (Path::toNativeSeparators (file.spath ()), max_total );
1053
1070
} else {
1054
1071
mTooManyConfigs = true ;
1055
1072
}
@@ -1069,30 +1086,14 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1069
1086
}
1070
1087
1071
1088
std::set<unsigned long long > hashes;
1072
- int checkCount = 0 ;
1073
1089
bool hasValidConfig = false ;
1074
1090
std::list<std::string> configurationError;
1075
- for (const std::string &currCfg : configurations ) {
1091
+ for (const std::string &currCfg : configs_total ) {
1076
1092
// bail out if terminated
1077
1093
if (Settings::terminated ())
1078
1094
break ;
1079
1095
1080
- // Check only a few configurations (default 12), after that bail out, unless --force
1081
- // was used.
1082
- if (!mSettings .force && ++checkCount > mSettings .maxConfigs )
1083
- break ;
1084
-
1085
- if (!mSettings .userDefines .empty ()) {
1086
- mCurrentConfig = mSettings .userDefines ;
1087
- const std::vector<std::string> v1 (split (mSettings .userDefines , " ;" ));
1088
- for (const std::string &cfg: split (currCfg, " ;" )) {
1089
- if (std::find (v1.cbegin (), v1.cend (), cfg) == v1.cend ()) {
1090
- mCurrentConfig += " ;" + cfg;
1091
- }
1092
- }
1093
- } else {
1094
- mCurrentConfig = currCfg;
1095
- }
1096
+ mCurrentConfig = currCfg;
1096
1097
1097
1098
if (mSettings .preprocessOnly ) {
1098
1099
std::string codeWithoutCfg;
@@ -1132,7 +1133,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1132
1133
mLogger ->setLocationMacros (tokenizer.tokens (), files);
1133
1134
1134
1135
// If only errors are printed, print filename after the check
1135
- if (!mSettings .quiet && (!mCurrentConfig .empty () || checkCount > 1 )) {
1136
+ if (!mSettings .quiet && (!mCurrentConfig .empty ())) {
1136
1137
std::string fixedpath = Path::toNativeSeparators (file.spath ());
1137
1138
mErrorLogger .reportOut (" Checking " + fixedpath + " : " + mCurrentConfig + " ..." , Color::FgGreen);
1138
1139
}
@@ -1187,9 +1188,8 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1187
1188
} catch (const simplecpp::Output &o) {
1188
1189
// #error etc during preprocessing
1189
1190
configurationError.push_back ((mCurrentConfig .empty () ? " \'\' " : mCurrentConfig ) + " : [" + o.location .file () + ' :' + std::to_string (o.location .line ) + " ] " + o.msg );
1190
- --checkCount; // don't count invalid configurations
1191
1191
1192
- if (!hasValidConfig && currCfg == *configurations .rbegin ()) {
1192
+ if (!hasValidConfig && currCfg == *configs_total .rbegin ()) {
1193
1193
// If there is no valid configuration then report error..
1194
1194
std::string locfile = Path::fromNativeSeparators (o.location .file ());
1195
1195
if (mSettings .relativePaths )
@@ -1218,7 +1218,7 @@ unsigned int CppCheck::checkFile(const FileWithDetails& file, const std::string
1218
1218
}
1219
1219
}
1220
1220
1221
- if (!hasValidConfig && configurations .size () > 1 && mSettings .severity .isEnabled (Severity::information)) {
1221
+ if (!hasValidConfig && configs_total .size () > 1 && mSettings .severity .isEnabled (Severity::information)) {
1222
1222
std::string msg;
1223
1223
msg = " This file is not analyzed. Cppcheck failed to extract a valid configuration. Use -v for more details." ;
1224
1224
msg += " \n This file is not analyzed. Cppcheck failed to extract a valid configuration. The tested configurations have these preprocessor errors:" ;
0 commit comments