Skip to content

Commit

Permalink
fix: crash if samples have different amount of costs associated
Browse files Browse the repository at this point in the history
If we have a recording with the following layout: A B C where
A: part where function f is accessed
B: list samples
C: part where function g is accessed
then f won't have the lost events cost while g does.
This will cause a crash when the model tries to access it

fixes: #629
  • Loading branch information
lievenhey committed May 13, 2024
1 parent 0cdebbb commit 93ec535
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/models/callercalleemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,26 @@ class LocationCostModelImpl : public HashModel<Data::SourceLocationCostMap, Mode
QVariant cell(int column, int role, const Data::FileLine& fileLine,
const Data::LocationCost& costs) const final override
{
// if we have a recording with the following layout: A B C where
// A: part where function f is accessed
// B: list samples
// C: part where function g is accessed
// then f won't have the lost events cost while g does.
// This will cause a crash when the model tries to access it

const std::size_t costType = column - NUM_BASE_COLUMNS;
auto safeSelfCost = costType < costs.selfCost.size() ? costs.selfCost[costType] : 0;
auto safeInclusiceCost = costType < costs.inclusiveCost.size() ? costs.selfCost[costType] : 0;
if (role == SortRole) {
if (column == Location) {
return QVariant::fromValue(fileLine);
}
column -= NUM_BASE_COLUMNS;
if (column < m_totalCosts.numTypes()) {
return costs.selfCost[column];
return safeSelfCost;
}
column -= m_totalCosts.numTypes();
return costs.inclusiveCost[column];
return safeInclusiceCost;
} else if (role == TotalCostRole && column >= NUM_BASE_COLUMNS) {
column -= NUM_BASE_COLUMNS;
if (column >= m_totalCosts.numTypes()) {
Expand All @@ -289,10 +299,10 @@ class LocationCostModelImpl : public HashModel<Data::SourceLocationCostMap, Mode
}
column -= NUM_BASE_COLUMNS;
if (column < m_totalCosts.numTypes()) {
return Util::formatCostRelative(costs.selfCost[column], m_totalCosts.totalCost(column), true);
return Util::formatCostRelative(safeSelfCost, m_totalCosts.totalCost(column), true);
}
column -= m_totalCosts.numTypes();
return Util::formatCostRelative(costs.inclusiveCost[column], m_totalCosts.totalCost(column), true);
return Util::formatCostRelative(safeInclusiceCost, m_totalCosts.totalCost(column), true);
} else if (role == FileLineRole) {
return QVariant::fromValue(fileLine);
} else if (role == Qt::ToolTipRole) {
Expand Down

0 comments on commit 93ec535

Please sign in to comment.