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) {