changeset 854:c17719e488c9

Fix some potential null-pointer derefs, and simplify some logic where loops were used with an unconditional "break" that meant they could only happen once (from coverity scan)
author Chris Cannam
date Wed, 03 Sep 2014 12:04:22 +0100
parents 99f96cacde36
children 57efeb75880d
files view/Overview.cpp view/Pane.cpp
diffstat 2 files changed, 22 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/view/Overview.cpp	Wed Sep 03 11:53:43 2014 +0100
+++ b/view/Overview.cpp	Wed Sep 03 12:04:22 2014 +0100
@@ -27,7 +27,8 @@
 
 Overview::Overview(QWidget *w) :
     View(w, false),
-    m_clickedInRange(false)
+    m_clickedInRange(false),
+    m_dragCentreFrame(0)
 {
     setObjectName(tr("Overview"));
     m_followPan = false;
--- a/view/Pane.cpp	Wed Sep 03 11:53:43 2014 +0100
+++ b/view/Pane.cpp	Wed Sep 03 12:04:22 2014 +0100
@@ -419,10 +419,10 @@
 
     if (e) paint.setClipRect(r);
 
-    ViewManager::ToolMode toolMode = m_manager->getToolModeFor(this);
+    ViewManager::ToolMode toolMode = ViewManager::NavigateMode;
+    if (m_manager) toolMode = m_manager->getToolModeFor(this);
 
     if (m_manager &&
-//        !m_manager->isPlaying() &&
         m_mouseInWidget &&
         toolMode == ViewManager::MeasureMode) {
 
@@ -495,6 +495,7 @@
     paint.setPen(QColor(50, 50, 50));
 
     if (waveformModel &&
+        sampleRate &&
         m_manager &&
         m_manager->shouldShowDuration()) {
         drawDurationAndRate(r, waveformModel, sampleRate, paint);
@@ -1093,8 +1094,9 @@
 
     if (m_scaleWidth > 0) {
 
-        for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) {
-            --vi;
+        Layer *layer = getTopLayer();
+
+        if (layer) {
             
             paint.save();
             
@@ -1103,12 +1105,11 @@
             paint.drawRect(xorigin, -1, m_scaleWidth, height()+1);
             
             paint.setBrush(Qt::NoBrush);
-            (*vi)->paintVerticalScale
+            layer->paintVerticalScale
                 (this, m_manager->shouldShowVerticalColourScale(),
                  paint, QRect(xorigin, 0, m_scaleWidth, height()));
             
             paint.restore();
-            break;
         }
     }
 
@@ -1127,12 +1128,11 @@
     int formerScaleWidth = m_scaleWidth;
             
     if (m_manager && m_manager->shouldShowVerticalScale()) {
-        for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) {
-            --vi;
+        Layer *layer = getTopLayer();
+        if (layer) {
             QPainter paint(image);
-            m_scaleWidth = (*vi)->getVerticalScaleWidth
+            m_scaleWidth = layer->getVerticalScaleWidth
                 (this, m_manager->shouldShowVerticalColourScale(), paint);
-            break;
         }
     } else {
         m_scaleWidth = 0;
@@ -1164,11 +1164,10 @@
 
     int sw = 0;
     if (m_manager && m_manager->shouldShowVerticalScale()) {
-        for (LayerList::iterator vi = m_layerStack.end(); vi != m_layerStack.begin(); ) {
-            --vi;
-            sw = (*vi)->getVerticalScaleWidth
+        Layer *layer = getTopLayer();
+        if (layer) {
+            sw = layer->getVerticalScaleWidth
                 (this, m_manager->shouldShowVerticalColourScale(), paint);
-            break;
         }
     }
     
@@ -1454,7 +1453,7 @@
 void
 Pane::mouseReleaseEvent(QMouseEvent *e)
 {
-    if (e->buttons() & Qt::RightButton) {
+    if (e && (e->buttons() & Qt::RightButton)) {
         return;
     }
 
@@ -1582,7 +1581,7 @@
 void
 Pane::mouseMoveEvent(QMouseEvent *e)
 {
-    if (e->buttons() & Qt::RightButton) {
+    if (!e || (e->buttons() & Qt::RightButton)) {
         return;
     }
 
@@ -1634,7 +1633,7 @@
             }
         }
 
-        if (!m_manager->isPlaying()) {
+        if (m_manager && !m_manager->isPlaying()) {
 
             bool updating = false;
 
@@ -1651,8 +1650,7 @@
                 }
             }
 
-            if (!updating && mode == ViewManager::MeasureMode &&
-                m_manager && !m_manager->isPlaying()) {
+            if (!updating && mode == ViewManager::MeasureMode) {
 
                 Layer *layer = getTopLayer();
                 if (layer && layer->nearestMeasurementRectChanged
@@ -2127,7 +2125,8 @@
 
     bool doScroll = false;
     if (!m_manager) doScroll = true;
-    if (!m_manager->isPlaying()) doScroll = true;
+    else if (!m_manager->isPlaying()) doScroll = true;
+
     if (m_followPlay != PlaybackScrollContinuous) doScroll = true;
 
     if (doScroll) {
@@ -2173,7 +2172,7 @@
 
     if (mode == ViewManager::SelectMode) {
         m_clickedInRange = false;
-        m_manager->clearInProgressSelection();
+        if (m_manager) m_manager->clearInProgressSelection();
         emit doubleClickSelectInvoked(getFrameForX(e->x()));
         return;
     }