Prevent off-by-one data access in chart models.
authorMilian Wolff <mail@milianw.de>
Thu, 24 Mar 2016 22:49:19 +0000 (23:49 +0100)
committerMilian Wolff <mail@milianw.de>
Thu, 24 Mar 2016 22:49:19 +0000 (23:49 +0100)
gui/chartmodel.cpp
gui/parser.cpp

index 85092e6..b914b38 100644 (file)
@@ -159,6 +159,7 @@ int ChartModel::rowCount(const QModelIndex& parent) const
 
 void ChartModel::resetData(const ChartData& data)
 {
+    Q_ASSERT(m_data.labels.size() < ChartRows::MAX_NUM_COST);
     beginResetModel();
     m_data = data;
     endResetModel();
index a1c74e4..cc1d4b8 100644 (file)
@@ -168,7 +168,7 @@ struct ParserData final : public AccumulatedTraceData
             sort(merged.begin(), merged.end(), [=] (const ChartMergeData& left, const ChartMergeData& right) {
                 return left.*member > right.*member;
             });
-            for (size_t i = 0; i < min(size_t(ChartRows::MAX_NUM_COST), merged.size()); ++i) {
+            for (size_t i = 0; i < min(size_t(ChartRows::MAX_NUM_COST - 1), merged.size()); ++i) {
                 const auto& alloc = merged[i];
                 if (!(alloc.*member)) {
                     break;