Skip to content

Commit 4cfdd11

Browse files
lievenheymilianw
authored andcommitted
fix: crash in disassembler on hover
When hovering the disassembler tries to create an tooltip. If the user hovers on the disassembly column or an earlier one, the model calculates a negative cost type which will cause an out of bounds access error in the cost array, even if the cost is not shown. This patch changes the order of operations and adds an check to make sure no out of bound access happens. fixes: #642
1 parent eb05bea commit 4cfdd11

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/models/disassemblymodel.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,28 +132,31 @@ QVariant DisassemblyModel::data(const QModelIndex& index, int role) const
132132
auto it = entry.offsetMap.find(data.addr);
133133
if (it != entry.offsetMap.end()) {
134134
const auto event = index.column() - COLUMN_COUNT;
135-
136135
const auto& locationCost = it.value();
136+
137+
if (role == Qt::ToolTipRole) {
138+
auto tooltip = tr("addr: <tt>%1</tt><br/>assembly: <tt>%2</tt><br/>disassembly: <tt>%3</tt>")
139+
.arg(QString::number(data.addr, 16), line);
140+
return Util::formatTooltip(tooltip, locationCost, m_results.selfCosts);
141+
}
142+
143+
if (event < 0)
144+
return {};
145+
137146
const auto& costLine = locationCost.selfCost[event];
138147
const auto totalCost = m_results.selfCosts.totalCost(event);
139148

140149
if (role == CostRole) {
141150
return costLine;
142151
} else if (role == TotalCostRole) {
143152
return totalCost;
144-
} else if (role == Qt::ToolTipRole) {
145-
auto tooltip = tr("addr: <tt>%1</tt><br/>assembly: <tt>%2</tt><br/>disassembly: <tt>%3</tt>")
146-
.arg(QString::number(data.addr, 16), line);
147-
return Util::formatTooltip(tooltip, locationCost, m_results.selfCosts);
148-
}
149-
150-
if (!costLine)
153+
} else if (!costLine)
151154
return {};
152155
return Util::formatCostRelative(costLine, totalCost, true);
153156
} else {
154-
if (role == Qt::ToolTipRole)
157+
if (role == Qt::ToolTipRole) {
155158
return tr("<qt><tt>%1</tt><hr/>No samples at this location.</qt>").arg(line.toHtmlEscaped());
156-
else
159+
} else
157160
return QString();
158161
}
159162
} else if (role == DisassemblyModel::HighlightRole) {

0 commit comments

Comments
 (0)