From 23599428cb488f79d7f94ef1a558ec7c9fffd8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 3 Feb 2019 19:49:27 +0100 Subject: [PATCH] Clarify Cppcheck output --- lib/cppcheck.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index c3a7a1999..57f3c30df 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -54,6 +54,19 @@ static TimerResults S_timerResults; // CWE ids used static const CWE CWE398(398U); // Indicator of Poor Code Quality +static std::vector split(const std::string &str, const std::string &sep) +{ + std::vector 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) : 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) break; - mCurrentConfig = currCfg; - if (!mSettings.userDefines.empty()) { - if (!mCurrentConfig.empty()) - mCurrentConfig = ";" + mCurrentConfig; - mCurrentConfig = mSettings.userDefines + mCurrentConfig; + mCurrentConfig = mSettings.userDefines; + const std::vector v1(split(mSettings.userDefines, ";")); + 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) {