diff --git a/cppcheck-errors.rng b/cppcheck-errors.rng index a2a5168b0..ed20228c9 100644 --- a/cppcheck-errors.rng +++ b/cppcheck-errors.rng @@ -17,20 +17,6 @@ - - - - 0 - - - - - - - 1 - - - @@ -55,13 +41,27 @@ + + + + + + + + + 0 + + + + + + + 1 + + + - - - - - diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index 37dd8c0d9..d398fa8a5 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -123,6 +123,8 @@ void XmlReportV2::writeError(const ErrorItem &error) mXmlWriter->writeAttribute(CWEAttribute, QString::number(error.cwe)); if (error.hash > 0) mXmlWriter->writeAttribute(HashAttribute, QString::number(error.hash)); + if (!error.file0.isEmpty()) + mXmlWriter->writeAttribute(IncludedFromFilenameAttribute, quoteMessage(error.file0)); if (!error.sinceDate.isEmpty()) mXmlWriter->writeAttribute(SinceDateAttribute, error.sinceDate); if (!error.tags.isEmpty()) @@ -132,9 +134,6 @@ void XmlReportV2::writeError(const ErrorItem &error) mXmlWriter->writeStartElement(LocationElementName); QString file = QDir::toNativeSeparators(error.errorPath[i].file); - if (!error.file0.isEmpty() && file != error.file0) { - mXmlWriter->writeAttribute(IncludedFromFilenameAttribute, quoteMessage(error.file0)); - } mXmlWriter->writeAttribute(FilenameAttribute, XmlReport::quoteMessage(file)); mXmlWriter->writeAttribute(LineAttribute, QString::number(error.errorPath[i].line)); if (error.errorPath[i].column > 0) @@ -218,6 +217,8 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader) item.cwe = attribs.value(QString(), CWEAttribute).toInt(); if (attribs.hasAttribute(QString(), HashAttribute)) item.hash = attribs.value(QString(), HashAttribute).toULongLong(); + if (attribs.hasAttribute(QString(), IncludedFromFilenameAttribute)) + item.file0 = attribs.value(QString(), IncludedFromFilenameAttribute).toString(); if (attribs.hasAttribute(QString(), SinceDateAttribute)) item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString(); if (attribs.hasAttribute(QString(), TagsAttribute)) diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index ee6bccf76..5c1c65059 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -270,6 +270,7 @@ std::string ErrorMessage::serialize() const oss << Severity::toString(severity).length() << " " << Severity::toString(severity); oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id); oss << MathLib::toString(hash).length() << " " << MathLib::toString(hash); + oss << file0.size() << " " << file0; if (certainty == Certainty::inconclusive) { const std::string text("inconclusive"); oss << text.length() << " " << text; @@ -296,9 +297,9 @@ bool ErrorMessage::deserialize(const std::string &data) certainty = Certainty::normal; callStack.clear(); std::istringstream iss(data); - std::array results; + std::array results; std::size_t elem = 0; - while (iss.good() && elem < 6) { + while (iss.good() && elem < 7) { unsigned int len = 0; if (!(iss >> len)) return false; @@ -318,15 +319,16 @@ bool ErrorMessage::deserialize(const std::string &data) results[elem++] = temp; } - if (elem != 6) + if (elem != 7) throw InternalError(nullptr, "Internal Error: Deserialization of error message failed"); id = results[0]; severity = Severity::fromString(results[1]); std::istringstream(results[2]) >> cwe.id; std::istringstream(results[3]) >> hash; - mShortMessage = results[4]; - mVerboseMessage = results[5]; + std::istringstream(results[4]) >> file0; + mShortMessage = results[5]; + mVerboseMessage = results[6]; unsigned int stackSize = 0; if (!(iss >> stackSize)) @@ -438,10 +440,11 @@ std::string ErrorMessage::toXML() const if (certainty == Certainty::inconclusive) printer.PushAttribute("inconclusive", "true"); + if (!file0.empty()) + printer.PushAttribute("file0", file0.c_str()); + for (std::list::const_reverse_iterator it = callStack.rbegin(); it != callStack.rend(); ++it) { printer.OpenElement("location", false); - if (!file0.empty() && (*it).getfile() != file0) - printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str()); printer.PushAttribute("file", (*it).getfile().c_str()); printer.PushAttribute("line", std::max((*it).line,0)); printer.PushAttribute("column", (*it).column);