Skip to content

Commit 6ec0641

Browse files
author
William Jakobsson
committed
fix: strip trailing string from Misra C id extraction
1 parent 6913517 commit 6ec0641

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

lib/errorlogger.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,13 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
10801080
case ReportType::misraC2012:
10811081
case ReportType::misraC2023:
10821082
case ReportType::misraC2025:
1083-
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0)
1084-
guideline = errId.substr(errId.rfind('-') + 1);
1083+
if (errId.rfind("misra-c20", 0) == 0 || errId.rfind("premium-misra-c-20", 0) == 0) {
1084+
auto dashPos = errId.rfind('-');
1085+
while (dashPos != std::string::npos && isalpha(errId[dashPos + 1])) {
1086+
dashPos = errId.rfind('-', dashPos - 1);
1087+
}
1088+
guideline = errId.substr(dashPos + 1, errId.find('-', dashPos + 1) - dashPos - 1);
1089+
}
10851090
break;
10861091
case ReportType::misraCpp2008:
10871092
if (errId.rfind("premium-misra-cpp-2008", 0) == 0)

test/testerrorlogger.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,8 @@ class TestErrorLogger : public TestFixture {
361361
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-dir-0.3.2", "Required", "Dir 0.3.2");
362362
testReportType(ReportType::misraCpp2008, Severity::style, "premium-misra-cpp-2008-3-4-1", "Required", "3-4-1");
363363
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-dir-4.6", "Advisory", "Dir 4.6");
364+
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-10.4-positive-number", "Required", "10.4");
365+
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-10.4", "Required", "10.4");
364366
testReportType(ReportType::misraC2012, Severity::style, "misra-c2012-dir-4.6", "Advisory", "Dir 4.6");
365367
testReportType(ReportType::certC, Severity::error, "resourceLeak", "L3", "FIO42-C");
366368
}

0 commit comments

Comments
 (0)