Clarify Cppcheck output

This commit is contained in:
Daniel Marjamäki 2019-02-03 19:49:27 +01:00
parent 437800f46d
commit 23599428cb
1 changed files with 22 additions and 5 deletions

View File

@ -54,6 +54,19 @@ static TimerResults S_timerResults;
// CWE ids used // CWE ids used
static const CWE CWE398(398U); // Indicator of Poor Code Quality static const CWE CWE398(398U); // Indicator of Poor Code Quality
static std::vector<std::string> split(const std::string &str, const std::string &sep)
{
std::vector<std::string> ret;
for (std::string::size_type defineStartPos = 0U; defineStartPos < str.size();) {
const std::string::size_type defineEndPos = str.find(sep, defineStartPos);
ret.push_back((defineEndPos == std::string::npos) ? str.substr(defineStartPos) : str.substr(defineStartPos, defineEndPos - defineStartPos));
if (defineEndPos == std::string::npos)
break;
defineStartPos = defineEndPos + 1U;
}
return ret;
}
CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions) CppCheck::CppCheck(ErrorLogger &errorLogger, bool useGlobalSuppressions)
: mErrorLogger(errorLogger), mExitCode(0), mSuppressInternalErrorFound(false), mUseGlobalSuppressions(useGlobalSuppressions), mTooManyConfigs(false), mSimplify(true) : mErrorLogger(errorLogger), mExitCode(0), mSuppressInternalErrorFound(false), mUseGlobalSuppressions(useGlobalSuppressions), mTooManyConfigs(false), mSimplify(true)
{ {
@ -325,12 +338,16 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
if (!mSettings.force && ++checkCount > mSettings.maxConfigs) if (!mSettings.force && ++checkCount > mSettings.maxConfigs)
break; break;
mCurrentConfig = currCfg;
if (!mSettings.userDefines.empty()) { if (!mSettings.userDefines.empty()) {
if (!mCurrentConfig.empty()) mCurrentConfig = mSettings.userDefines;
mCurrentConfig = ";" + mCurrentConfig; const std::vector<std::string> v1(split(mSettings.userDefines, ";"));
mCurrentConfig = mSettings.userDefines + mCurrentConfig; for (const std::string &cfg: split(currCfg, ";")) {
if (std::find(v1.begin(), v1.end(), cfg) == v1.end()) {
mCurrentConfig += ";" + cfg;
}
}
} else {
mCurrentConfig = currCfg;
} }
if (mSettings.preprocessOnly) { if (mSettings.preprocessOnly) {