diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index 5bcac762c45..0421e36e3ca 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -33,6 +33,16 @@ static bool isCppcheckPremium(const Settings& settings) { return (settings.cppcheckCfgProductName.compare(0, 16, "Cppcheck Premium") == 0); } +static int getMisraCVersion(const Settings& settings) { + if (settings.premiumArgs.find("misra-c-2012") != std::string::npos) + return 2012; + if (settings.premiumArgs.find("misra-c-2023") != std::string::npos) + return 2023; + if (settings.addons.count("misra")) + return 2012; + return 0; +} + static bool isMisraRuleActive(const std::set& activeCheckers, const std::string& rule) { if (activeCheckers.count("Misra C: " + rule)) return true; @@ -229,29 +239,23 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const reportSection("Cert C", mSettings, mActiveCheckers, checkers::premiumCheckers, "Cert C: "); reportSection("Cert C++", mSettings, mActiveCheckers, checkers::premiumCheckers, "Cert C++: "); - int misra = 0; - if (mSettings.premiumArgs.find("misra-c-2012") != std::string::npos) - misra = 2012; - else if (mSettings.premiumArgs.find("misra-c-2023") != std::string::npos) - misra = 2023; - else if (mSettings.addons.count("misra")) - misra = 2012; + const int misraCVersion = getMisraCVersion(mSettings); - if (misra == 0) { + if (misraCVersion == 0) { fout << std::endl << std::endl; fout << "Misra C" << std::endl; fout << "-------" << std::endl; fout << "Misra is not enabled" << std::endl; } else { fout << std::endl << std::endl; - fout << "Misra C " << misra << std::endl; + fout << "Misra C " << misraCVersion << std::endl; fout << "------------" << std::endl; for (const checkers::MisraInfo& info: checkers::misraC2012Directives) { const std::string directive = "Dir " + std::to_string(info.a) + "." + std::to_string(info.b); const bool active = isMisraRuleActive(mActiveCheckers, directive); - fout << (active ? "Yes " : "No ") << "Misra C " << misra << ": " << directive; + fout << (active ? "Yes " : "No ") << "Misra C " << misraCVersion << ": " << directive; std::string extra; - if (misra == 2012 && info.amendment >= 1) + if (misraCVersion == 2012 && info.amendment >= 1) extra = " amendment:" + std::to_string(info.amendment); if (!extra.empty()) fout << std::string(10 - directive.size(), ' ') << extra; @@ -260,9 +264,9 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const for (const checkers::MisraInfo& info: checkers::misraC2012Rules) { const std::string rule = std::to_string(info.a) + "." + std::to_string(info.b); const bool active = isMisraRuleActive(mActiveCheckers, rule); - fout << (active ? "Yes " : "No ") << "Misra C " << misra << ": " << rule; + fout << (active ? "Yes " : "No ") << "Misra C " << misraCVersion << ": " << rule; std::string extra; - if (misra == 2012 && info.amendment >= 1) + if (misraCVersion == 2012 && info.amendment >= 1) extra = " amendment:" + std::to_string(info.amendment); std::string reqs; if (info.amendment >= 3) @@ -284,84 +288,17 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const std::string CheckersReport::getXmlReport(const std::string& criticalErrors) const { std::string ret; - - if (!criticalErrors.empty()) { - ret += " " + criticalErrors + "\n \n"; - } else + if (!criticalErrors.empty()) + ret += " " + criticalErrors + "\n"; + else ret += " \n"; ret += " \n"; - - const bool cppcheckPremium = isCppcheckPremium(mSettings); - - auto reportSection = [&ret, cppcheckPremium] - (const std::string& title, - const Settings& settings, - const std::set& activeCheckers, - const std::map& premiumCheckers, - const std::string& substring) { - if (!cppcheckPremium) { - ret += "<" + title + "/>\n"; - return; - } - ret += " <" + title + ">\n"; - for (const auto& checkReq: premiumCheckers) { - const std::string& checker = checkReq.first; - if (checker.find(substring) == std::string::npos) - continue; - bool active = cppcheckPremium && activeCheckers.count(checker) > 0; - if (substring == "::") { - if (checkReq.second == "warning") - active &= settings.severity.isEnabled(Severity::warning); - else if (checkReq.second == "style") - active &= settings.severity.isEnabled(Severity::style); - else if (checkReq.second == "portability") - active &= settings.severity.isEnabled(Severity::portability); - else if (!checkReq.second.empty()) - active = false; // FIXME: handle req - } - ret += " \n"; - }; - - reportSection("premium-checkers", mSettings, mActiveCheckers, checkers::premiumCheckers, "::"); - reportSection("autosar", mSettings, mActiveCheckers, checkers::premiumCheckers, "Autosar: "); - reportSection("cert-c", mSettings, mActiveCheckers, checkers::premiumCheckers, "Cert C: "); - reportSection("cert-cpp", mSettings, mActiveCheckers, checkers::premiumCheckers, "Cert C++: "); - - int misra = 0; - if (mSettings.premiumArgs.find("misra-c-2012") != std::string::npos) - misra = 2012; - else if (mSettings.premiumArgs.find("misra-c-2023") != std::string::npos) - misra = 2023; - else if (mSettings.addons.count("misra")) - misra = 2012; - - if (misra == 0) { - ret += " \n"; - } else { - ret += " \n"; - for (const checkers::MisraInfo& info: checkers::misraC2012Directives) { - const std::string directive = "Dir " + std::to_string(info.a) + "." + std::to_string(info.b); - const bool active = isMisraRuleActive(mActiveCheckers, directive); - ret += " \n"; + const int misraCVersion = getMisraCVersion(mSettings); + for (std::string checker: mActiveCheckers) { + if (checker.compare(0,8,"Misra C:") == 0) + checker = "Misra C " + std::to_string(misraCVersion) + ":" + checker.substr(8); + ret += " \n"; } - - reportSection("misra-cpp-2008", mSettings, mActiveCheckers, checkers::premiumCheckers, "Misra C++ 2008: "); - reportSection("misra-cpp-2023", mSettings, mActiveCheckers, checkers::premiumCheckers, "Misra C++ 2023: "); - ret += " "; return ret; } diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index bd907f724c1..11616b362fd 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -450,7 +450,7 @@ std::string ErrorMessage::getXMLHeader(std::string productName, int xmlVersion) std::string ErrorMessage::getXMLFooter(int xmlVersion) { - return xmlVersion == 3? "" : " \n"; + return xmlVersion == 3 ? "" : " \n"; } // There is no utf-8 support around but the strings should at least be safe for to tinyxml2.