Skip to content

Commit f077ec4

Browse files
authored
Fix #14011 (crash: GUI crash when trying to hide a result from xml file) (danmar#7985)
1 parent 12d0391 commit f077ec4

File tree

13 files changed

+600
-654
lines changed

13 files changed

+600
-654
lines changed

gui/erroritem.cpp

Lines changed: 27 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
@@ -95,3 +96,19 @@ bool ErrorItem::sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2
9596
errorItem1.inconclusive == errorItem2.inconclusive &&
9697
errorItem1.severity == errorItem2.severity;
9798
}
99+
100+
bool ErrorItem::filterMatch(const QString& filter) const
101+
{
102+
if (filter.isEmpty())
103+
return true;
104+
if (summary.contains(filter, Qt::CaseInsensitive) ||
105+
message.contains(filter, Qt::CaseInsensitive) ||
106+
errorId.contains(filter, Qt::CaseInsensitive) ||
107+
classification.contains(filter, Qt::CaseInsensitive))
108+
return true;
109+
return std::any_of(errorPath.cbegin(), errorPath.cend(),
110+
[filter](const auto& e) {
111+
return e.file.contains(filter, Qt::CaseInsensitive) ||
112+
e.info.contains(filter, Qt::CaseInsensitive);
113+
});
114+
}

gui/erroritem.h

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,20 @@ 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+
96+
bool filterMatch(const QString& filter) const;
97+
8498
QString file0;
8599
QString errorId;
86100
Severity severity;
@@ -100,33 +114,9 @@ class ErrorItem {
100114
QString tags;
101115

102116
/**
103-
* Compare "CID"
117+
* Compare Hash and fields
104118
*/
105-
static bool sameCID(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
119+
static bool same(const ErrorItem &errorItem1, const ErrorItem &errorItem2);
106120
};
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;
129-
};
130-
131121
/// @}
132122
#endif // ERRORITEM_H

gui/resultitem.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2025 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#include "resultitem.h"
20+
21+
ResultItem::ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex)
22+
: errorItem(std::move(errorItem)), mType(type), mErrorPathIndex(errorPathIndex)
23+
{}

gui/resultitem.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* -*- C++ -*-
2+
* Cppcheck - A tool for static C/C++ code analysis
3+
* Copyright (C) 2007-2025 Cppcheck team.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
#ifndef RESULTITEM_H
20+
#define RESULTITEM_H
21+
22+
#include "erroritem.h"
23+
#include <QStandardItem>
24+
#include <QSharedPointer>
25+
26+
class ResultItem : public QStandardItem
27+
{
28+
public:
29+
enum class Type: std::uint8_t {file, message, note};
30+
31+
ResultItem(QSharedPointer<ErrorItem> errorItem, Type type, int errorPathIndex);
32+
QSharedPointer<ErrorItem> errorItem;
33+
bool hidden{};
34+
35+
QErrorPathItem getErrorPathItem() const {
36+
if (!errorItem || mErrorPathIndex < 0 || mErrorPathIndex >= errorItem->errorPath.size())
37+
return {};
38+
return errorItem->errorPath[mErrorPathIndex];
39+
}
40+
41+
Type getType() const {
42+
return mType;
43+
}
44+
private:
45+
const Type mType;
46+
const int mErrorPathIndex;
47+
};
48+
49+
#endif // RESULTITEM_H

0 commit comments

Comments
 (0)