XML: Ensure file0 info is kept in multithreaded analysis. Write file0 attribute in top <error> element instead of in the <location> elements.
This commit is contained in:
parent
e65ea8575f
commit
161ea81fd8
|
@ -17,20 +17,6 @@
|
|||
<element name="errors">
|
||||
<zeroOrMore>
|
||||
<element name="error">
|
||||
<optional>
|
||||
<attribute name="cwe">
|
||||
<data type="integer">
|
||||
<param name="minExclusive">0</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="hash">
|
||||
<data type="integer">
|
||||
<param name="minExclusive">1</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</optional>
|
||||
<attribute name="id">
|
||||
<data type="NCName"/>
|
||||
</attribute>
|
||||
|
@ -55,13 +41,27 @@
|
|||
<attribute name="verbose">
|
||||
<data type="string"/>
|
||||
</attribute>
|
||||
<optional>
|
||||
<attribute name="file0">
|
||||
<data type="string"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="cwe">
|
||||
<data type="integer">
|
||||
<param name="minExclusive">0</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="hash">
|
||||
<data type="integer">
|
||||
<param name="minExclusive">1</param>
|
||||
</data>
|
||||
</attribute>
|
||||
</optional>
|
||||
<zeroOrMore>
|
||||
<element name="location">
|
||||
<optional>
|
||||
<attribute name="file0">
|
||||
<data type="string"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<attribute name="file">
|
||||
<data type="string"/>
|
||||
</attribute>
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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<std::string, 6> results;
|
||||
std::array<std::string, 7> 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<FileLocation>::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);
|
||||
|
|
Loading…
Reference in New Issue