Skip to content

Commit a8c250f

Browse files
committed
fix #13730
1 parent c5387a2 commit a8c250f

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ void StdLogger::reportErr(const ErrorMessage &msg)
670670
ErrorMessage msgCopy = msg;
671671
msgCopy.guideline = getGuideline(msgCopy.id, mSettings.reportType,
672672
mGuidelineMapping, msgCopy.severity);
673-
msgCopy.classification = getClassification(msgCopy.guideline, mSettings.reportType);
673+
msgCopy.classification = getClassification(msgCopy.id, msgCopy.guideline, mSettings.reportType);
674674

675675
// TODO: there should be no need for verbose and default messages here
676676
const std::string msgStr = msgCopy.toString(mSettings.verbose, mSettings.templateFormat, mSettings.templateLocation);

lib/errorlogger.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ void substituteTemplateLocationStatic(std::string& templateLocation)
925925
replaceColors(templateLocation);
926926
}
927927

928-
std::string getClassification(const std::string &guideline, ReportType reportType) {
928+
std::string getClassification(const std::string &errId, const std::string &guideline, ReportType reportType) {
929929
if (guideline.empty())
930930
return "";
931931

@@ -954,15 +954,16 @@ std::string getClassification(const std::string &guideline, ReportType reportTyp
954954
const int a = std::stoi(components[0]);
955955
const int b = std::stoi(components[1]);
956956

957-
const std::vector<checkers::MisraInfo> &info = checkers::misraC2012Rules;
957+
const bool isDirective = errId.find("dir") != std::string::npos;
958+
const std::vector<checkers::MisraInfo> &info = isDirective ? checkers::misraC2012Directives : checkers::misraC2012Rules;
958959
const auto it = std::find_if(info.cbegin(), info.cend(), [&](const checkers::MisraInfo &i) {
959960
return i.a == a && i.b == b;
960961
});
961962

962-
if (it == info.cend())
963-
return "";
963+
if (it != info.cend())
964+
return it->str;
964965

965-
return it->str;
966+
return "";
966967
}
967968
case ReportType::misraCpp2008:
968969
case ReportType::misraCpp2023:

lib/errorlogger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ CPPCHECKLIB void substituteTemplateFormatStatic(std::string& templateFormat);
295295
CPPCHECKLIB void substituteTemplateLocationStatic(std::string& templateLocation);
296296

297297
/** Get a classification string from the given guideline and reporttype */
298-
CPPCHECKLIB std::string getClassification(const std::string &guideline, ReportType reportType);
298+
CPPCHECKLIB std::string getClassification(const std::string &errId, const std::string &guideline, ReportType reportType);
299299

300300
/** Get a guidline string froM the given error id, reporttype, mapping and severity */
301301
CPPCHECKLIB std::string getGuideline(const std::string &errId, ReportType reportType,

test/testerrorlogger.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class TestErrorLogger : public TestFixture {
323323
const std::string format = "{severity} {id}";
324324
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "unusedVariable", Certainty::normal);
325325
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
326-
msg.classification = getClassification(msg.guideline, reportType);
326+
msg.classification = getClassification(msg.id, msg.guideline, reportType);
327327
ASSERT_EQUALS("Advisory", msg.classification);
328328
ASSERT_EQUALS("2.8", msg.guideline);
329329
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
@@ -349,7 +349,7 @@ class TestErrorLogger : public TestFixture {
349349
const std::string format = "{severity} {id}";
350350
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "resourceLeak", Certainty::normal);
351351
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
352-
msg.classification = getClassification(msg.guideline, reportType);
352+
msg.classification = getClassification(msg.id, msg.guideline, reportType);
353353
ASSERT_EQUALS("L3", msg.classification);
354354
ASSERT_EQUALS("FIO42-C", msg.guideline);
355355
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format, ""));

0 commit comments

Comments
 (0)