# HG changeset patch # User Chris Cannam # Date 1453475796 0 # Node ID 69c4f8403ebf9271d60caf2e60c9644d15b9807e # Parent 25ec2390fad33089796e599a87de25f97e5997ce Fix integer overflow in getFrameForX diff -r 25ec2390fad3 -r 69c4f8403ebf view/View.cpp --- a/view/View.cpp Fri Jan 22 13:39:45 2016 +0000 +++ b/view/View.cpp Fri Jan 22 15:16:36 2016 +0000 @@ -49,7 +49,6 @@ //#define DEBUG_VIEW 1 //#define DEBUG_VIEW_WIDGET_PAINT 1 - View::View(QWidget *w, bool showProgress) : QFrame(w), m_centreFrame(0), @@ -365,15 +364,17 @@ sv_frame_t View::getFrameForX(int x) const { - int z = m_zoomLevel; + sv_frame_t z = m_zoomLevel; // nb not just int, or multiplication may overflow sv_frame_t frame = m_centreFrame - (width()/2) * z; + frame = (frame / z) * z; // this is start frame + frame = frame + x * z; + #ifdef DEBUG_VIEW_WIDGET_PAINT - SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; + cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; #endif - frame = (frame / z) * z; // this is start frame - return frame + x * z; + return frame; } double