Skip to content

Commit 161ea81

Browse files
committed
XML: Ensure file0 info is kept in multithreaded analysis. Write file0 attribute in top <error> element instead of in the <location> elements.
1 parent e65ea85 commit 161ea81

3 files changed

Lines changed: 33 additions & 29 deletions

File tree

cppcheck-errors.rng

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,6 @@
1717
<element name="errors">
1818
<zeroOrMore>
1919
<element name="error">
20-
<optional>
21-
<attribute name="cwe">
22-
<data type="integer">
23-
<param name="minExclusive">0</param>
24-
</data>
25-
</attribute>
26-
</optional>
27-
<optional>
28-
<attribute name="hash">
29-
<data type="integer">
30-
<param name="minExclusive">1</param>
31-
</data>
32-
</attribute>
33-
</optional>
3420
<attribute name="id">
3521
<data type="NCName"/>
3622
</attribute>
@@ -55,13 +41,27 @@
5541
<attribute name="verbose">
5642
<data type="string"/>
5743
</attribute>
44+
<optional>
45+
<attribute name="file0">
46+
<data type="string"/>
47+
</attribute>
48+
</optional>
49+
<optional>
50+
<attribute name="cwe">
51+
<data type="integer">
52+
<param name="minExclusive">0</param>
53+
</data>
54+
</attribute>
55+
</optional>
56+
<optional>
57+
<attribute name="hash">
58+
<data type="integer">
59+
<param name="minExclusive">1</param>
60+
</data>
61+
</attribute>
62+
</optional>
5863
<zeroOrMore>
5964
<element name="location">
60-
<optional>
61-
<attribute name="file0">
62-
<data type="string"/>
63-
</attribute>
64-
</optional>
6565
<attribute name="file">
6666
<data type="string"/>
6767
</attribute>

gui/xmlreportv2.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ void XmlReportV2::writeError(const ErrorItem &error)
123123
mXmlWriter->writeAttribute(CWEAttribute, QString::number(error.cwe));
124124
if (error.hash > 0)
125125
mXmlWriter->writeAttribute(HashAttribute, QString::number(error.hash));
126+
if (!error.file0.isEmpty())
127+
mXmlWriter->writeAttribute(IncludedFromFilenameAttribute, quoteMessage(error.file0));
126128
if (!error.sinceDate.isEmpty())
127129
mXmlWriter->writeAttribute(SinceDateAttribute, error.sinceDate);
128130
if (!error.tags.isEmpty())
@@ -132,9 +134,6 @@ void XmlReportV2::writeError(const ErrorItem &error)
132134
mXmlWriter->writeStartElement(LocationElementName);
133135

134136
QString file = QDir::toNativeSeparators(error.errorPath[i].file);
135-
if (!error.file0.isEmpty() && file != error.file0) {
136-
mXmlWriter->writeAttribute(IncludedFromFilenameAttribute, quoteMessage(error.file0));
137-
}
138137
mXmlWriter->writeAttribute(FilenameAttribute, XmlReport::quoteMessage(file));
139138
mXmlWriter->writeAttribute(LineAttribute, QString::number(error.errorPath[i].line));
140139
if (error.errorPath[i].column > 0)
@@ -218,6 +217,8 @@ ErrorItem XmlReportV2::readError(QXmlStreamReader *reader)
218217
item.cwe = attribs.value(QString(), CWEAttribute).toInt();
219218
if (attribs.hasAttribute(QString(), HashAttribute))
220219
item.hash = attribs.value(QString(), HashAttribute).toULongLong();
220+
if (attribs.hasAttribute(QString(), IncludedFromFilenameAttribute))
221+
item.file0 = attribs.value(QString(), IncludedFromFilenameAttribute).toString();
221222
if (attribs.hasAttribute(QString(), SinceDateAttribute))
222223
item.sinceDate = attribs.value(QString(), SinceDateAttribute).toString();
223224
if (attribs.hasAttribute(QString(), TagsAttribute))

lib/errorlogger.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ std::string ErrorMessage::serialize() const
270270
oss << Severity::toString(severity).length() << " " << Severity::toString(severity);
271271
oss << MathLib::toString(cwe.id).length() << " " << MathLib::toString(cwe.id);
272272
oss << MathLib::toString(hash).length() << " " << MathLib::toString(hash);
273+
oss << file0.size() << " " << file0;
273274
if (certainty == Certainty::inconclusive) {
274275
const std::string text("inconclusive");
275276
oss << text.length() << " " << text;
@@ -296,9 +297,9 @@ bool ErrorMessage::deserialize(const std::string &data)
296297
certainty = Certainty::normal;
297298
callStack.clear();
298299
std::istringstream iss(data);
299-
std::array<std::string, 6> results;
300+
std::array<std::string, 7> results;
300301
std::size_t elem = 0;
301-
while (iss.good() && elem < 6) {
302+
while (iss.good() && elem < 7) {
302303
unsigned int len = 0;
303304
if (!(iss >> len))
304305
return false;
@@ -318,15 +319,16 @@ bool ErrorMessage::deserialize(const std::string &data)
318319
results[elem++] = temp;
319320
}
320321

321-
if (elem != 6)
322+
if (elem != 7)
322323
throw InternalError(nullptr, "Internal Error: Deserialization of error message failed");
323324

324325
id = results[0];
325326
severity = Severity::fromString(results[1]);
326327
std::istringstream(results[2]) >> cwe.id;
327328
std::istringstream(results[3]) >> hash;
328-
mShortMessage = results[4];
329-
mVerboseMessage = results[5];
329+
std::istringstream(results[4]) >> file0;
330+
mShortMessage = results[5];
331+
mVerboseMessage = results[6];
330332

331333
unsigned int stackSize = 0;
332334
if (!(iss >> stackSize))
@@ -438,10 +440,11 @@ std::string ErrorMessage::toXML() const
438440
if (certainty == Certainty::inconclusive)
439441
printer.PushAttribute("inconclusive", "true");
440442

443+
if (!file0.empty())
444+
printer.PushAttribute("file0", file0.c_str());
445+
441446
for (std::list<FileLocation>::const_reverse_iterator it = callStack.rbegin(); it != callStack.rend(); ++it) {
442447
printer.OpenElement("location", false);
443-
if (!file0.empty() && (*it).getfile() != file0)
444-
printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str());
445448
printer.PushAttribute("file", (*it).getfile().c_str());
446449
printer.PushAttribute("line", std::max((*it).line,0));
447450
printer.PushAttribute("column", (*it).column);

0 commit comments

Comments
 (0)