From 55adeb44339539f523fd021aca11ea39162f9047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 19 Aug 2024 20:34:40 +0200 Subject: [PATCH] Fix #13029 (Update checkers report: Misra C directives) (#6712) --- lib/checkers.cpp | 25 +++++++++++++++++++++++++ lib/checkers.h | 1 + lib/checkersreport.cpp | 13 ++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/lib/checkers.cpp b/lib/checkers.cpp index 9e7a69608a7..de11e6574af 100644 --- a/lib/checkers.cpp +++ b/lib/checkers.cpp @@ -836,6 +836,31 @@ namespace checkers { const char Man[] = "Mandatory"; const char Doc[] = "Document"; + const std::vector misraC2012Directives = + { + {1,1,Req,0}, + {2,1,Req,0}, + {3,1,Req,0}, + {4,1,Req,0}, + {4,2,Adv,0}, + {4,3,Req,0}, + {4,4,Adv,0}, + {4,5,Adv,0}, + {4,6,Adv,3}, + {4,7,Req,0}, + {4,8,Adv,0}, + {4,9,Adv,3}, + {4,10,Req,0}, + {4,11,Req,3}, + {4,12,Req,0}, + {4,13,Adv,0}, + {4,14,Req,2}, + {4,15,Req,3}, + {5,1,Req,4}, + {5,2,Req,4}, + {5,3,Req,4}, + }; + const std::vector misraC2012Rules = { {1,1,Req,0}, diff --git a/lib/checkers.h b/lib/checkers.h index 13f9570172e..bbf8d1b06ce 100644 --- a/lib/checkers.h +++ b/lib/checkers.h @@ -48,6 +48,7 @@ namespace checkers { extern CPPCHECKLIB const char Man[]; // = "Mandatory"; extern CPPCHECKLIB const char Doc[]; // = "Document"; + extern CPPCHECKLIB const std::vector misraC2012Directives; extern CPPCHECKLIB const std::vector misraC2012Rules; extern CPPCHECKLIB const std::vector misraCpp2008Rules; extern CPPCHECKLIB const std::vector misraCpp2023Rules; diff --git a/lib/checkersreport.cpp b/lib/checkersreport.cpp index 3391a8edfd8..770523c45ed 100644 --- a/lib/checkersreport.cpp +++ b/lib/checkersreport.cpp @@ -241,6 +241,17 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const fout << std::endl << std::endl; fout << "Misra C " << misra << 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; + std::string extra; + if (misra == 2012 && info.amendment >= 1) + extra = " amendment:" + std::to_string(info.amendment); + if (!extra.empty()) + fout << std::string(10 - directive.size(), ' ') << extra; + fout << '\n'; + } 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); @@ -254,7 +265,7 @@ std::string CheckersReport::getReport(const std::string& criticalErrors) const if (!active && !reqs.empty()) extra += " require:" + reqs.substr(1); if (!extra.empty()) - fout << std::string(7 - rule.size(), ' ') << extra; + fout << std::string(10 - rule.size(), ' ') << extra; fout << '\n'; } }