GUI: Write cppcheck-id in xml report

This commit is contained in:
Daniel Marjamäki 2020-07-15 07:59:05 +02:00
parent af0db3cc21
commit 260c53ba6f
5 changed files with 21 additions and 5 deletions

View File

@ -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<ErrorMessage::FileLocation>::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 &&

View File

@ -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<QErrorPathItem> 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;

View File

@ -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();

View File

@ -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)

View File

@ -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))