forked from qt-creator/qt-creator
Fix crashes when accssing invalid indexes
Change-Id: I412490ded92803daaf6d5a1850e53b6072a42e7d Reviewed-by: Christiaan Janssen <christiaan.janssen@digia.com>
This commit is contained in:
@@ -229,12 +229,12 @@ const QString PaintEventsModelProxy::categoryLabel(int categoryIndex) const
|
|||||||
int PaintEventsModelProxy::findFirstIndex(qint64 startTime) const
|
int PaintEventsModelProxy::findFirstIndex(qint64 startTime) const
|
||||||
{
|
{
|
||||||
if (d->eventList.isEmpty())
|
if (d->eventList.isEmpty())
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->eventList.count() == 1 || d->eventList.first().startTime+d->eventList.first().duration >= startTime)
|
if (d->eventList.count() == 1 || d->eventList.first().startTime+d->eventList.first().duration >= startTime)
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else
|
||||||
if (d->eventList.last().startTime+d->eventList.last().duration <= startTime)
|
if (d->eventList.last().startTime+d->eventList.last().duration <= startTime)
|
||||||
return 0; // -1
|
return -1;
|
||||||
|
|
||||||
int fromIndex = 0;
|
int fromIndex = 0;
|
||||||
int toIndex = d->eventList.count()-1;
|
int toIndex = d->eventList.count()-1;
|
||||||
@@ -256,9 +256,9 @@ int PaintEventsModelProxy::findFirstIndexNoParents(qint64 startTime) const
|
|||||||
int PaintEventsModelProxy::findLastIndex(qint64 endTime) const
|
int PaintEventsModelProxy::findLastIndex(qint64 endTime) const
|
||||||
{
|
{
|
||||||
if (d->eventList.isEmpty())
|
if (d->eventList.isEmpty())
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->eventList.first().startTime >= endTime)
|
if (d->eventList.first().startTime >= endTime)
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->eventList.count() == 1)
|
if (d->eventList.count() == 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (d->eventList.last().startTime <= endTime)
|
if (d->eventList.last().startTime <= endTime)
|
||||||
|
|||||||
@@ -452,12 +452,12 @@ int BasicTimelineModel::findFirstIndex(qint64 startTime) const
|
|||||||
int candidate = -1;
|
int candidate = -1;
|
||||||
// in the "endtime" list, find the first event that ends after startTime
|
// in the "endtime" list, find the first event that ends after startTime
|
||||||
if (d->endTimeData.isEmpty())
|
if (d->endTimeData.isEmpty())
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
|
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
|
||||||
candidate = 0;
|
candidate = 0;
|
||||||
else
|
else
|
||||||
if (d->endTimeData.last().endTime <= startTime)
|
if (d->endTimeData.last().endTime <= startTime)
|
||||||
return 0; // -1
|
return -1;
|
||||||
|
|
||||||
if (candidate == -1)
|
if (candidate == -1)
|
||||||
{
|
{
|
||||||
@@ -484,12 +484,12 @@ int BasicTimelineModel::findFirstIndexNoParents(qint64 startTime) const
|
|||||||
int candidate = -1;
|
int candidate = -1;
|
||||||
// in the "endtime" list, find the first event that ends after startTime
|
// in the "endtime" list, find the first event that ends after startTime
|
||||||
if (d->endTimeData.isEmpty())
|
if (d->endTimeData.isEmpty())
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
|
if (d->endTimeData.count() == 1 || d->endTimeData.first().endTime >= startTime)
|
||||||
candidate = 0;
|
candidate = 0;
|
||||||
else
|
else
|
||||||
if (d->endTimeData.last().endTime <= startTime)
|
if (d->endTimeData.last().endTime <= startTime)
|
||||||
return 0; // -1
|
return -1;
|
||||||
|
|
||||||
if (candidate == -1) {
|
if (candidate == -1) {
|
||||||
int fromIndex = 0;
|
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
|
// in the "starttime" list, find the last event that starts before endtime
|
||||||
if (d->startTimeData.isEmpty())
|
if (d->startTimeData.isEmpty())
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->startTimeData.first().startTime >= endTime)
|
if (d->startTimeData.first().startTime >= endTime)
|
||||||
return 0; // -1
|
return -1;
|
||||||
if (d->startTimeData.count() == 1)
|
if (d->startTimeData.count() == 1)
|
||||||
return 0;
|
return 0;
|
||||||
if (d->startTimeData.last().startTime <= endTime)
|
if (d->startTimeData.last().startTime <= endTime)
|
||||||
|
|||||||
@@ -83,14 +83,16 @@ void TimelineRenderer::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWid
|
|||||||
|
|
||||||
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
|
for (int modelIndex = 0; modelIndex < m_profilerModelProxy->modelCount(); modelIndex++) {
|
||||||
int lastIndex = m_profilerModelProxy->findLastIndex(modelIndex, m_endTime);
|
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);
|
int firstIndex = m_profilerModelProxy->findFirstIndex(modelIndex, m_startTime);
|
||||||
|
if (firstIndex >= 0) {
|
||||||
drawItemsToPainter(p, modelIndex, firstIndex, lastIndex);
|
drawItemsToPainter(p, modelIndex, firstIndex, lastIndex);
|
||||||
if (m_selectedModel == modelIndex)
|
if (m_selectedModel == modelIndex)
|
||||||
drawSelectionBoxes(p, modelIndex, firstIndex, lastIndex);
|
drawSelectionBoxes(p, modelIndex, firstIndex, lastIndex);
|
||||||
drawBindingLoopMarkers(p, modelIndex, firstIndex, lastIndex);
|
drawBindingLoopMarkers(p, modelIndex, firstIndex, lastIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
m_lastStartTime = m_startTime;
|
m_lastStartTime = m_startTime;
|
||||||
m_lastEndTime = m_endTime;
|
m_lastEndTime = m_endTime;
|
||||||
|
|
||||||
@@ -311,7 +313,8 @@ void TimelineRenderer::manageHovered(int x, int y)
|
|||||||
// find if there's items in the time range
|
// find if there's items in the time range
|
||||||
int eventFrom = m_profilerModelProxy->findFirstIndex(modelIndex, time);
|
int eventFrom = m_profilerModelProxy->findFirstIndex(modelIndex, time);
|
||||||
int eventTo = m_profilerModelProxy->findLastIndex(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;
|
m_currentSelection.eventIndex = -1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -457,7 +460,8 @@ void TimelineRenderer::selectPrev()
|
|||||||
int candidateModelIndex = -1;
|
int candidateModelIndex = -1;
|
||||||
qint64 candidateStartTime = m_profilerModelProxy->traceStartTime();
|
qint64 candidateStartTime = m_profilerModelProxy->traceStartTime();
|
||||||
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
for (int i = 0; i < m_profilerModelProxy->modelCount(); i++) {
|
||||||
if (itemIndexes[i] == -1)
|
if (itemIndexes[i] == -1
|
||||||
|
|| itemIndexes[i] >= m_profilerModelProxy->count(i))
|
||||||
continue;
|
continue;
|
||||||
qint64 newStartTime = m_profilerModelProxy->getStartTime(i, itemIndexes[i]);
|
qint64 newStartTime = m_profilerModelProxy->getStartTime(i, itemIndexes[i]);
|
||||||
if (newStartTime < searchTime && newStartTime > candidateStartTime) {
|
if (newStartTime < searchTime && newStartTime > candidateStartTime) {
|
||||||
@@ -493,6 +497,8 @@ int TimelineRenderer::nextItemFromId(int modelIndex, int eventId) const
|
|||||||
ndx = m_profilerModelProxy->findFirstIndexNoParents(modelIndex, m_startTime);
|
ndx = m_profilerModelProxy->findFirstIndexNoParents(modelIndex, m_startTime);
|
||||||
else
|
else
|
||||||
ndx = m_selectedItem + 1;
|
ndx = m_selectedItem + 1;
|
||||||
|
if (ndx < 0)
|
||||||
|
return -1;
|
||||||
if (ndx >= m_profilerModelProxy->count(modelIndex))
|
if (ndx >= m_profilerModelProxy->count(modelIndex))
|
||||||
ndx = 0;
|
ndx = 0;
|
||||||
int startIndex = ndx;
|
int startIndex = ndx;
|
||||||
|
|||||||
Reference in New Issue
Block a user