Skip to content

Commit 400f870

Browse files
authored
Fix #13074 (GUI: The guideline/classification is not always set correctly in CERT reports) (#6775)
1 parent 1527922 commit 400f870

1 file changed

Lines changed: 25 additions & 32 deletions

File tree

gui/resultstree.cpp

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -128,27 +128,21 @@ static QString getGuideline(ReportType reportType, const QMap<QString,QString>&
128128
static QString getClassification(ReportType reportType, const QString& guideline) {
129129
if (guideline.isEmpty())
130130
return QString();
131-
if (reportType == ReportType::autosar) {
132-
for (const checkers::Info& autosarInfo: checkers::autosarInfo) {
131+
auto getFromInfo = [](const std::vector<checkers::Info>& info, const QString& guideline) -> QString {
132+
for (const checkers::Info& i: info) {
133133
// cppcheck-suppress useStlAlgorithm
134-
if (guideline.compare(autosarInfo.guideline, Qt::CaseInsensitive))
135-
return autosarInfo.classification;
136-
}
137-
}
138-
else if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
139-
if (guideline.endsWith("-CPP")) {
140-
for (const checkers::Info& info: checkers::certCppInfo) {
141-
// cppcheck-suppress useStlAlgorithm
142-
if (guideline.compare(info.guideline, Qt::CaseInsensitive))
143-
return info.classification;
144-
}
145-
} else if (guideline.endsWith("-C")) {
146-
for (const checkers::Info& info: checkers::certCInfo) {
147-
// cppcheck-suppress useStlAlgorithm
148-
if (guideline.compare(info.guideline, Qt::CaseInsensitive))
149-
return info.classification;
150-
}
134+
if (guideline.compare(i.guideline, Qt::CaseInsensitive) == 0)
135+
return i.classification;
151136
}
137+
return QString();
138+
};
139+
if (reportType == ReportType::autosar)
140+
return getFromInfo(checkers::autosarInfo, guideline);
141+
if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
142+
if (guideline.endsWith("-CPP"))
143+
return getFromInfo(checkers::certCppInfo, guideline);
144+
if (guideline.endsWith("-C"))
145+
return getFromInfo(checkers::certCInfo, guideline);
152146
}
153147
else if (reportType == ReportType::misraC) {
154148
QStringList list = guideline.split(".");
@@ -268,26 +262,25 @@ void ResultsTree::keyPressEvent(QKeyEvent *event)
268262
void ResultsTree::setReportType(ReportType reportType) {
269263
mReportType = reportType;
270264

265+
auto readInfo = [this](const std::vector<checkers::Info>& info) {
266+
for (const auto& i: info)
267+
for (const QString& cppcheckId: QString(i.cppcheckIds).split(","))
268+
mGuideline[cppcheckId] = QString(i.guideline).toUpper();
269+
};
270+
271271
auto readIdMapping = [this](const std::vector<checkers::IdMapping>& idMapping) {
272272
for (const auto& i: idMapping)
273273
for (const QString& cppcheckId: QString(i.cppcheckId).split(","))
274274
mGuideline[cppcheckId] = i.guideline;
275275
};
276276

277-
if (reportType == ReportType::autosar) {
278-
for (const auto& a: checkers::autosarInfo) {
279-
mGuideline[a.cppcheckIds] = QString(a.guideline).toUpper();
280-
}
281-
}
282-
else if (reportType == ReportType::certC) {
283-
for (const auto& a: checkers::certCInfo)
284-
mGuideline[a.cppcheckIds] = QString(a.guideline).toUpper();
285-
}
277+
if (reportType == ReportType::autosar)
278+
readInfo(checkers::autosarInfo);
279+
else if (reportType == ReportType::certC)
280+
readInfo(checkers::certCInfo);
286281
else if (reportType == ReportType::certCpp) {
287-
for (const auto& a: checkers::certCInfo)
288-
mGuideline[a.cppcheckIds] = QString(a.guideline).toUpper();
289-
for (const auto& a: checkers::certCppInfo)
290-
mGuideline[a.cppcheckIds] = QString(a.guideline).toUpper();
282+
readInfo(checkers::certCInfo);
283+
readInfo(checkers::certCppInfo);
291284
}
292285
else if (reportType == ReportType::misraC)
293286
readIdMapping(checkers::idMappingMisraC);

0 commit comments

Comments
 (0)