aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@digia.com>2013-06-13 13:56:57 +0200
committerKai Koehne <kai.koehne@digia.com>2013-06-13 15:14:22 +0300
commit0e6180a7e4e4208a09dc87f7ad7f1a7b408985a6 (patch)
tree403ca79bdaa57bd88e8d4304fe5de1d6c7367dc1
parenta5e72ef87519546e160124d33b3b57cc02b1f365 (diff)
Fix crashes when accssing invalid indexes
Change-Id: I412490ded92803daaf6d5a1850e53b6072a42e7d Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
-rw-r--r--plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp8
-rw-r--r--plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp12
-rw-r--r--plugins/qmlprofiler/timelinerenderer.cpp20
3 files changed, 23 insertions, 17 deletions
diff --git a/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp b/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp
index 466c3461ea..12420eebbd 100644
--- a/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp
+++ b/plugins/qmlprofiler/qmlprofilerpainteventsmodelproxy.cpp
@@ -229,12 +229,12 @@ const QString PaintEventsModelProxy::categoryLabel(int categoryIndex) const
int PaintEventsModelProxy::findFirstIndex(qint64 startTime) const
{
if (d->eventList.isEmpty())
- return 0; // -1
+ return -1;
if (d->eventList.count() == 1 || d->eventList.first().startTime+d->eventList.first().duration >= startTime)
return 0;
else
if (d->eventList.last().startTime+d->eventList.last().duration <= startTime)
- return 0; // -1
+ return -1;
int fromIndex = 0;
int toIndex = d->eventList.count()-1;
@@ -256,9 +256,9 @@ int PaintEventsModelProxy::findFirstIndexNoParents(qint64 startTime) const
int PaintEventsModelProxy::findLastIndex(qint64 endTime) const
{
if (d->eventList.isEmpty())
- return 0; // -1
+ return -1;
if (d->eventList.first().startTime >= endTime)
- return 0; // -1
+ return -1;
if (d->eventList.count() == 1)
return 0;
if (d->eventList.last().startTime <= endTime)
diff --git a/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp b/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp
index dc3bc8752e..b0601e8719 100644
--- a/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp
+++ b/plugins/qmlprofiler/qmlprofilertimelinemodelproxy.cpp
@@ -452,12 +452,12 @@ int BasicTimelineModel::findFirstIndex(qint64 startTime) const
int candidate = -1;
// in the "endtime" list, find the first event that ends after startTime
if (d->endTimeData.isEmpty())
- return 0; // -1
+ return -1;
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
candidate = 0;
else
if (d->endTimeData.last().endTime <= startTime)
- return 0; // -1
+ return -1;
if (candidate == -1)
{
@@ -484,12 +484,12 @@ int BasicTimelineModel::findFirstIndexNoParents(qint64 startTime) const
int candidate = -1;
// in the "endtime" list, find the first event that ends after startTime
if (d->endTimeData.isEmpty())
- return 0; // -1
+ return -1;
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
candidate = 0;
else
if (d->endTimeData.last().endTime <= startTime)
- return 0; // -1
+ return -1;
if (candidate == -1) {
int fromIndex = 0;
@@ -514,9 +514,9 @@ int BasicTimelineModel::findLastIndex(qint64 endTime) const
{
// in the "starttime" list, find the last event that starts before endtime
if (d->startTimeData.isEmpty())
- return 0; // -1
+ return -1;
if (d->startTimeData.first().startTime >= endTime)
- return 0; // -1
+ return -1;
if (d->startTimeData.count() == 1)
return 0;
if (d->startTimeData.last().startTime <= endTime)
diff --git a/plugins/qmlprofiler/timelinerenderer.cpp b/plugins/qmlprofiler/timelinerenderer.cpp
index 741e357989..e31dd6c473 100644
--- a/plugins/qmlprofiler/timelinerenderer.cpp
+++ b/plugins/qmlprofiler/timelinerenderer.cpp
@@ -83,12 +83,14 @@ void TimelineRenderer::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
int lastIndex = m_profilerModelProxy->findLastIndex(modelIndex, m_endTime);
- if (lastIndex < m_profilerModelProxy->count(modelIndex)) {
+ if (lastIndex >= 0 && lastIndex < m_profilerModelProxy->count(modelIndex)) {
int firstIndex = m_profilerModelProxy->findFirstIndex(modelIndex, m_startTime);
- drawItemsToPainter(p, modelIndex, firstIndex, lastIndex);
- if (m_selectedModel == modelIndex)
- drawSelectionBoxes(p, modelIndex, firstIndex, lastIndex);
- drawBindingLoopMarkers(p, modelIndex, firstIndex, lastIndex);
+ if (firstIndex >= 0) {
+ drawItemsToPainter(p, modelIndex, firstIndex, lastIndex);
+ if (m_selectedModel == modelIndex)
+ drawSelectionBoxes(p, modelIndex, firstIndex, lastIndex);
+ drawBindingLoopMarkers(p, modelIndex, firstIndex, lastIndex);
+ }
}
}
m_lastStartTime = m_startTime;
@@ -311,7 +313,8 @@ void TimelineRenderer::manageHovered(int x, int y)
// find if there's items in the time range
int eventFrom = m_profilerModelProxy->findFirstIndex(modelIndex, time);
int eventTo = m_profilerModelProxy->findLastIndex(modelIndex, time);
- if (eventTo < eventFrom || eventTo >= m_profilerModelProxy->count()) {
+ if (eventFrom == -1 ||
+ eventTo < eventFrom || eventTo >= m_profilerModelProxy->count()) {
m_currentSelection.eventIndex = -1;
return;
}
@@ -457,7 +460,8 @@ void TimelineRenderer::selectPrev()
int candidateModelIndex = -1;
qint64 candidateStartTime = m_profilerModelProxy->traceStartTime();
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
- if (itemIndexes[i] == -1)
+ if (itemIndexes[i] == -1
+ || itemIndexes[i] >= m_profilerModelProxy->count(i))
continue;
qint64 newStartTime = m_profilerModelProxy->getStartTime(i, itemIndexes[i]);
if (newStartTime < searchTime && newStartTime > candidateStartTime) {
@@ -493,6 +497,8 @@ int TimelineRenderer::nextItemFromId(int modelIndex, int eventId) const
ndx = m_profilerModelProxy->findFirstIndexNoParents(modelIndex, m_startTime);
else
ndx = m_selectedItem + 1;
+ if (ndx < 0)
+ return -1;
if (ndx >= m_profilerModelProxy->count(modelIndex))
ndx = 0;
int startIndex = ndx;