diff data/model/Dense3DModelPeakCache.h @ 1192:9884efa1f88a spectrogram-minor-refactor

Fix potential crash in Dense3dModelPeakCache owing to combination of wrong width calculation and wrong handling of width overrun
author Chris Cannam
date Thu, 14 Jul 2016 14:49:04 +0100
parents 6d09ad2ab21f
children df59bf0b4236
line wrap: on
line diff
--- a/data/model/Dense3DModelPeakCache.h	Wed Jul 13 13:06:28 2016 +0100
+++ b/data/model/Dense3DModelPeakCache.h	Thu Jul 14 14:49:04 2016 +0100
@@ -53,7 +53,12 @@
     }
     
     virtual int getWidth() const {
-        return m_source->getWidth() / m_columnsPerPeak + 1;
+        int sourceWidth = m_source->getWidth();
+        if ((sourceWidth % m_columnsPerPeak) == 0) {
+            return sourceWidth / m_columnsPerPeak;
+        } else {
+            return sourceWidth / m_columnsPerPeak + 1;
+        }
     }
 
     virtual int getHeight() const {