Skip to content

Commit ea62f1f

Browse files
committed
Fix #14011 (crash: GUI crash when trying to hide a result from xml file)
1 parent cb76e52 commit ea62f1f

File tree

9 files changed

+387
-556
lines changed

9 files changed

+387
-556
lines changed

gui/erroritem.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,22 @@ QString ErrorItem::tool() const
7070

7171
QString ErrorItem::toString() const
7272
{
73-
QString str = errorPath.back().file + " - " + errorId + " - ";
73+
const int i = getMainLocIndex();
74+
QString ret = errorPath[i].file + ":" + QString::number(errorPath[i].line) + ":" + QString::number(errorPath[i].column) + ":";
75+
ret += GuiSeverity::toString(severity);
7476
if (inconclusive)
75-
str += "inconclusive ";
76-
str += GuiSeverity::toString(severity) +"\n";
77-
str += summary + "\n";
78-
str += message + "\n";
79-
for (const QErrorPathItem& i : errorPath) {
80-
str += " " + i.file + ": " + QString::number(i.line) + "\n";
77+
ret += ",inconclusive";
78+
ret += ": " + summary + " [" + errorId + "]";
79+
if (errorPath.size() >= 2) {
80+
for (const auto& e: errorPath)
81+
ret += "\n" + e.file + ":" + QString::number(e.line) + ":" + QString::number(e.column) + ":note: " + e.info;
8182
}
82-
return str;
83+
return ret;
8384
}
8485

85-
bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
86+
bool ErrorItem::same(const ErrorItem &errorItem1, const ErrorItem &errorItem2)
8687
{
87-
if (errorItem1.hash || errorItem2.hash)
88+
if (errorItem1.hash && errorItem2.hash)
8889
return errorItem1.hash == errorItem2.hash;
8990

9091
// fallback

gui/erroritem.h

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ class ErrorItem {
8181
QString toString() const;
8282
QString tool() const;
8383

84+
int getMainLocIndex() const {
85+
return isClangResult() ? 0 : errorPath.size() - 1;
86+
}
87+
88+
QString getFile() const {
89+
return errorPath.isEmpty() ? QString() : errorPath[getMainLocIndex()].file;
90+
}
91+
92+
bool isClangResult() const {
93+
return errorId.startsWith("clang");
94+
}
95+
8496
QString file0;
8597
QString errorId;
8698
Severity severity;
@@ -100,33 +112,9 @@ class ErrorItem {
100112
QString tags;
101113

102114
/**
103-
* Compare "CID"
115+
* Compare Hash and fields
104116
*/
105-
static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
106-
};
107-
108-
// NOLINTNEXTLINE(performance-no-int-to-ptr)
109-
Q_DECLARE_METATYPE(ErrorItem)
110-
111-
/**
112-
* @brief A class containing error data for one shown error line.
113-
*/
114-
class ErrorLine {
115-
public:
116-
QString file;
117-
int line;
118-
QString file0;
119-
QString errorId;
120-
int cwe;
121-
unsigned long long hash;
122-
bool inconclusive;
123-
Severity severity;
124-
QString summary;
125-
QString message;
126-
QString sinceDate;
127-
QString tags;
128-
QString remark;
117+
static bool same(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
129118
};
130-
131119
/// @}
132120
#endif // ERRORITEM_H

gui/resultitem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include "resultitem.h"
2+
3+
ResultItem::ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex)
4+
: errorItem(errorItem), mType(type), mErrorPathIndex(errorPathIndex)
5+
{
6+
}

gui/resultitem.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef RESULTITEM_H
2+
#define RESULTITEM_H
3+
4+
#include <QStandardItem>
5+
#include "erroritem.h"
6+
#include <QSharedPointer>
7+
8+
class ResultItem : public QStandardItem
9+
{
10+
public:
11+
enum class Type {file, message, note};
12+
13+
ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex);
14+
QSharedPointer<ErrorItem> errorItem;
15+
bool hidden{};
16+
17+
QErrorPathItem getErrorPathItem() const {
18+
if (!errorItem || errorItem->errorPath.isEmpty())
19+
return {};
20+
return errorItem->errorPath[mErrorPathIndex];
21+
}
22+
23+
Type getType() const {
24+
return mType;
25+
}
26+
private:
27+
const Type mType;
28+
const int mErrorPathIndex;
29+
};
30+
31+
#endif // RESULTITEM_H

0 commit comments

Comments
 (0)