Skip to content

Commit 5bf67a9

Browse files
committed
Fix getClassification crash
1 parent 25af75e commit 5bf67a9

4 files changed

Lines changed: 21 additions & 9 deletions

File tree

lib/checkers.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,14 @@ namespace checkers {
19011901
{27,0,1,Req}
19021902
};
19031903

1904+
const std::vector<MisraCppInfo> misraCpp2023Directives =
1905+
{
1906+
{0,3,1,Adv},
1907+
{0,3,2,Req},
1908+
{5,7,2,Adv},
1909+
{15,8,1,Req},
1910+
};
1911+
19041912
const std::vector<MisraCppInfo> misraCpp2023Rules =
19051913
{
19061914
{0,0,1,Req},
@@ -1911,15 +1919,12 @@ namespace checkers {
19111919
{0,2,2,Req},
19121920
{0,2,3,Adv},
19131921
{0,2,4,Adv},
1914-
{0,3,1,Adv},
1915-
{0,3,2,Req},
19161922
{4,1,1,Req},
19171923
{4,1,2,Adv},
19181924
{4,1,3,Req},
19191925
{4,6,1,Req},
19201926
{5,0,1,Adv},
19211927
{5,7,1,Req},
1922-
{5,7,2,Adv},
19231928
{5,7,3,Req},
19241929
{5,10,1,Req},
19251930
{5,13,1,Req},
@@ -2025,7 +2030,6 @@ namespace checkers {
20252030
{15,1,3,Req},
20262031
{15,1,4,Adv},
20272032
{15,1,5,Req},
2028-
{15,8,1,Req},
20292033
{16,5,2,Req},
20302034
{16,6,1,Adv},
20312035
{17,8,1,Req},

lib/checkers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ namespace checkers {
6868
extern CPPCHECKLIB const std::vector<MisraInfo> misraC2025Directives;
6969
extern CPPCHECKLIB const std::vector<MisraInfo> misraC2025Rules;
7070
extern CPPCHECKLIB const std::vector<MisraCppInfo> misraCpp2008Rules;
71+
extern CPPCHECKLIB const std::vector<MisraCppInfo> misraCpp2023Directives;
7172
extern CPPCHECKLIB const std::vector<MisraCppInfo> misraCpp2023Rules;
7273

7374
struct CPPCHECKLIB IdMapping {

lib/errorlogger.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,17 +983,22 @@ std::string getClassification(const std::string &guideline, ReportType reportTyp
983983
case ReportType::misraCpp2008:
984984
case ReportType::misraCpp2023:
985985
{
986-
char delim;
987986
const std::vector<checkers::MisraCppInfo> *info;
987+
std::vector<std::string> components;
988+
988989
if (reportType == ReportType::misraCpp2008) {
989-
delim = '-';
990990
info = &checkers::misraCpp2008Rules;
991+
components = splitString(guideline, '-');
991992
} else {
992-
delim = '.';
993-
info = &checkers::misraCpp2023Rules;
993+
if (guideline.rfind("Dir ", 0) == 0) {
994+
components = splitString(guideline.substr(4), '.');
995+
info = &checkers::misraCpp2023Directives;
996+
} else {
997+
components = splitString(guideline, '.');
998+
info = &checkers::misraCpp2023Rules;
999+
}
9941000
}
9951001

996-
auto components = splitString(guideline, delim);
9971002
if (components.size() != 3)
9981003
return "";
9991004

test/testerrorlogger.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@ class TestErrorLogger : public TestFixture {
334334
testReportType(ReportType::misraC2012, Severity::error, "unusedVariable", "Advisory", "2.8");
335335
testReportType(ReportType::misraCpp2023, Severity::warning, "premium-misra-cpp-2023-6.8.4", "Advisory", "6.8.4");
336336
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-19.6.1", "Advisory", "19.6.1");
337+
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-dir-0.3.1", "Advisory", "Dir 0.3.1");
338+
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-dir-0.3.2", "Required", "Dir 0.3.2");
337339
testReportType(ReportType::misraCpp2008, Severity::style, "premium-misra-cpp-2008-3-4-1", "Required", "3-4-1");
338340
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-dir-4.6", "Advisory", "Dir 4.6");
339341
testReportType(ReportType::misraC2012, Severity::style, "misra-c2012-dir-4.6", "Advisory", "Dir 4.6");

0 commit comments

Comments
 (0)