From 260c53ba6f73e7395e11c6232aa78f6a1eb51639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Wed, 15 Jul 2020 07:59:05 +0200 Subject: [PATCH] GUI: Write cppcheck-id in xml report --- gui/erroritem.cpp | 9 +++++++-- gui/erroritem.h | 4 +++- gui/resultstree.cpp | 4 ++++ gui/resultsview.cpp | 2 +- gui/xmlreportv2.cpp | 7 ++++++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/gui/erroritem.cpp b/gui/erroritem.cpp index acf420204..cccc25911 100644 --- a/gui/erroritem.cpp +++ b/gui/erroritem.cpp @@ -37,6 +37,7 @@ ErrorItem::ErrorItem() , incomplete(false) , inconclusive(false) , cwe(-1) + , cppcheckId(0) { } @@ -50,6 +51,7 @@ ErrorItem::ErrorItem(const ErrorMessage &errmsg) , summary(QString::fromStdString(errmsg.shortMessage())) , message(QString::fromStdString(errmsg.verboseMessage())) , cwe(errmsg.cwe.id) + , cppcheckId(errmsg.cppcheckId) , symbolNames(QString::fromStdString(errmsg.symbolNames())) { for (std::list::const_iterator loc = errmsg.callStack.begin(); @@ -70,7 +72,7 @@ QString ErrorItem::tool() const return "cppcheck"; } -QString ErrorItem::ToString() const +QString ErrorItem::toString() const { QString str = errorPath.back().file + " - " + errorId + " - "; if (inconclusive) @@ -86,7 +88,10 @@ QString ErrorItem::ToString() const bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2) { - // TODO: Implement some better CID calculation + if (errorItem1.cppcheckId || errorItem2.cppcheckId) + return errorItem1.cppcheckId == errorItem2.cppcheckId; + + // fallback return errorItem1.errorId == errorItem2.errorId && errorItem1.errorPath == errorItem2.errorPath && errorItem1.file0 == errorItem2.file0 && diff --git a/gui/erroritem.h b/gui/erroritem.h index 96ed90e7d..7bcb9a74f 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -76,7 +76,7 @@ public: * @brief Convert error item to string. * @return Error item as string. */ - QString ToString() const; + QString toString() const; QString tool() const; QString file0; @@ -88,6 +88,7 @@ public: QString summary; QString message; int cwe; + unsigned long long cppcheckId; QList errorPath; QString symbolNames; @@ -114,6 +115,7 @@ public: QString errorId; bool incomplete; int cwe; + unsigned long long cppcheckId; bool inconclusive; Severity::SeverityType severity; QString summary; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index c3e3d4b22..cbb1e3b93 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -168,6 +168,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item) line.errorId = item.errorId; line.incomplete = item.incomplete; line.cwe = item.cwe; + line.cppcheckId = item.cppcheckId; line.inconclusive = item.inconclusive; line.summary = item.summary; line.message = item.message; @@ -197,6 +198,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item) data["id"] = item.errorId; data["incomplete"] = item.incomplete; data["cwe"] = item.cwe; + data["cppcheckId"] = item.cppcheckId; data["inconclusive"] = item.inconclusive; data["file0"] = stripPath(item.file0, true); data["function"] = item.function; @@ -232,6 +234,7 @@ bool ResultsTree::addErrorItem(const ErrorItem &item) child_data["id"] = line.errorId; child_data["incomplete"] = line.incomplete; child_data["cwe"] = line.cwe; + child_data["cppcheckId"] = line.cppcheckId; child_data["inconclusive"] = line.inconclusive; child_item->setData(QVariant(child_data)); } @@ -1221,6 +1224,7 @@ void ResultsTree::readErrorItem(const QStandardItem *error, ErrorItem *item) con item->errorId = data["id"].toString(); item->incomplete = data["incomplete"].toBool(); item->cwe = data["cwe"].toInt(); + item->cppcheckId = data["cppcheckId"].toULongLong(); item->inconclusive = data["inconclusive"].toBool(); item->file0 = data["file0"].toString(); item->sinceDate = data["sinceDate"].toString(); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 1dc0a294c..fcc88d73b 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -448,7 +448,7 @@ void ResultsView::log(const QString &str) void ResultsView::debugError(const ErrorItem &item) { - mUI.mListLog->addItem(item.ToString()); + mUI.mListLog->addItem(item.toString()); } void ResultsView::bughuntingReportLine(const QString& line) diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index f70053de5..5fac01c9e 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -34,6 +34,7 @@ static const QString ErrorElementName = "error"; static const QString ErrorsElementName = "errors"; static const QString LocationElementName = "location"; static const QString CWEAttribute = "cwe"; +static const QString CppcheckIdAttribute = "cppcheck-id"; static const QString SinceDateAttribute = "sinceDate"; static const QString TagsAttribute = "tag"; static const QString FilenameAttribute = "file"; @@ -122,6 +123,8 @@ void XmlReportV2::writeError(const ErrorItem &error) mXmlWriter->writeAttribute(InconclusiveAttribute, "true"); if (error.cwe > 0) mXmlWriter->writeAttribute(CWEAttribute, QString::number(error.cwe)); + if (error.cppcheckId > 0) + mXmlWriter->writeAttribute(CppcheckIdAttribute, QString::number(error.cppcheckId)); if (!error.sinceDate.isEmpty()) mXmlWriter->writeAttribute(SinceDateAttribute, error.sinceDate); if (!error.tags.isEmpty()) @@ -214,7 +217,9 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader) if (attribs.hasAttribute(QString(), InconclusiveAttribute)) item.inconclusive = true; if (attribs.hasAttribute(QString(), CWEAttribute)) - item.cwe = attribs.value(QString(), CWEAttribute).toString().toInt(); + item.cwe = attribs.value(QString(), CWEAttribute).toInt(); + if (attribs.hasAttribute(QString(), CppcheckIdAttribute)) + item.cppcheckId = attribs.value(QString(), CWEAttribute).toULongLong(); if (attribs.hasAttribute(QString(), SinceDateAttribute)) item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString(); if (attribs.hasAttribute(QString(), TagsAttribute))