27 #include <unordered_set>
34 static bool isMisraRuleActive(
const std::set<std::string>& activeCheckers,
const std::string& rule) {
35 if (activeCheckers.count(
"Misra C: " + rule))
42 return activeCheckers.count(
"CheckCondition::alwaysTrueFalse") != 0;
44 return activeCheckers.count(
"CheckOther::checkUnusedLabel") != 0;
46 return activeCheckers.count(
"CheckUnusedVar::checkFunctionVariableUsage") != 0;
48 return activeCheckers.count(
"CheckOther::checkShadowVariables") != 0;
50 return activeCheckers.count(
"CheckOther::checkConstPointer") != 0;
54 return activeCheckers.count(
"CheckOther::checkConstPointer") != 0;
56 return activeCheckers.count(
"CheckCondition::alwaysTrueFalse") != 0;
58 return activeCheckers.count(
"CheckBufferOverrun::argumentSize") != 0;
60 return activeCheckers.count(
"CheckBufferOverrun::pointerArithmetic") != 0;
62 return activeCheckers.count(
"CheckOther::checkComparePointers") != 0;
64 return activeCheckers.count(
"CheckOther::checkComparePointers") != 0;
68 return activeCheckers.count(
"CheckOther::checkOverlappingWrite") != 0;
72 return activeCheckers.count(
"CheckFunctions::invalidFunctionUsage") != 0;
74 return activeCheckers.count(
"CheckBufferOverrun::bufferOverflow") != 0;
76 return activeCheckers.count(
"CheckBufferOverrun::bufferOverflow") != 0;
80 return activeCheckers.count(
"CheckAutoVariables::autoVariables") != 0;
82 return activeCheckers.count(
"CheckIO::checkFileUsage") != 0;
84 return activeCheckers.count(
"CheckIO::checkFileUsage") != 0;
86 return activeCheckers.count(
"CheckIO::checkFileUsage") != 0;
92 : mSettings(settings), mActiveCheckers(activeCheckers)
127 const std::string rule = std::to_string(info.a) +
"." + std::to_string(info.b);
138 std::ostringstream fout;
140 fout <<
"Critical errors" << std::endl;
141 fout <<
"---------------" << std::endl;
142 if (!criticalErrors.empty()) {
143 fout <<
"There was critical errors (" << criticalErrors <<
")" << std::endl;
144 fout <<
"All checking is skipped for a file with such error" << std::endl;
146 fout <<
"No critical errors, all files were checked." << std::endl;
147 fout <<
"Important: Analysis is still not guaranteed to be 'complete' it is possible there are false negatives." << std::endl;
150 fout << std::endl << std::endl;
151 fout <<
"Open source checkers" << std::endl;
152 fout <<
"--------------------" << std::endl;
154 int maxCheckerSize = 0;
156 const std::string& checker = checkReq.first;
157 if (checker.size() > maxCheckerSize)
158 maxCheckerSize = checker.size();
161 const std::string& checker = checkReq.first;
163 const std::string& req = checkReq.second;
164 fout << (active ?
"Yes " :
"No ") << checker;
165 if (!active && !req.empty())
166 fout << std::string(maxCheckerSize + 4 - checker.size(),
' ') <<
"require:" + req;
172 auto reportSection = [&fout, cppcheckPremium]
173 (
const std::string& title,
175 const std::set<std::string>& activeCheckers,
177 const std::string& substring) {
178 fout << std::endl << std::endl;
179 fout << title << std::endl;
180 fout << std::string(title.size(),
'-') << std::endl;
181 if (!cppcheckPremium) {
182 fout <<
"Not available, Cppcheck Premium is not used" << std::endl;
185 int maxCheckerSize = 0;
187 const std::string& checker = checkReq.first;
188 if (checker.find(substring) != std::string::npos && checker.size() > maxCheckerSize)
189 maxCheckerSize = checker.size();
192 const std::string& checker = checkReq.first;
193 if (checker.find(substring) == std::string::npos)
195 std::string req = checkReq.second;
196 bool active = cppcheckPremium && activeCheckers.count(checker) > 0;
197 if (substring ==
"::") {
198 if (req ==
"warning")
200 else if (req ==
"style")
202 else if (req ==
"portability")
204 else if (!req.empty())
207 fout << (active ?
"Yes " :
"No ") << checker;
208 if (!cppcheckPremium) {
210 req =
"premium," + req;
215 req =
"require:" + req;
217 fout << std::string(maxCheckerSize + 4 - checker.size(),
' ') << req;
236 fout << std::endl << std::endl;
237 fout <<
"Misra C" << std::endl;
238 fout <<
"-------" << std::endl;
239 fout <<
"Misra is not enabled" << std::endl;
241 fout << std::endl << std::endl;
242 fout <<
"Misra C " << misra << std::endl;
243 fout <<
"------------" << std::endl;
245 const std::string rule = std::to_string(info.a) +
"." + std::to_string(info.b);
247 fout << (active ?
"Yes " :
"No ") <<
"Misra C " << misra <<
": " << rule;
249 if (misra == 2012 && info.amendment >= 1)
250 extra =
" amendment:" + std::to_string(info.amendment);
252 if (info.amendment >= 3)
254 if (!active && !reqs.empty())
255 extra +=
" require:" + reqs.substr(1);
257 fout << std::string(7 - rule.size(),
' ') << extra;
static bool isCppcheckPremium(const Settings &settings)
static bool isMisraRuleActive(const std::set< std::string > &activeCheckers, const std::string &rule)
int getActiveCheckersCount()
std::string getReport(const std::string &criticalErrors) const
int getAllCheckersCount()
const Settings & mSettings
CheckersReport(const Settings &settings, const std::set< std::string > &activeCheckers)
const std::set< std::string > & mActiveCheckers
This is just a container for general settings so that we don't need to pass individual values to func...
std::unordered_set< std::string > addons
addons, either filename of python/json file or json data
std::string cppcheckCfgProductName
cppcheck.cfg: Custom product name
std::string premiumArgs
Extra arguments for Cppcheck Premium addon.
@ portability
Portability warning.
const std::vector< MisraInfo > misraC2012Rules
const std::map< std::string, std::string > premiumCheckers
const std::map< std::string, std::string > allCheckers