Mercurial > hg > svgui
comparison view/View.cpp @ 1020:69c4f8403ebf colourschemes
Fix integer overflow in getFrameForX
author | Chris Cannam |
---|---|
date | Fri, 22 Jan 2016 15:16:36 +0000 |
parents | 5fdf5cd032ac |
children | 4e5c1c326794 |
comparison
equal
deleted
inserted
replaced
1019:25ec2390fad3 | 1020:69c4f8403ebf |
---|---|
46 | 46 |
47 #include <unistd.h> | 47 #include <unistd.h> |
48 | 48 |
49 //#define DEBUG_VIEW 1 | 49 //#define DEBUG_VIEW 1 |
50 //#define DEBUG_VIEW_WIDGET_PAINT 1 | 50 //#define DEBUG_VIEW_WIDGET_PAINT 1 |
51 | |
52 | 51 |
53 View::View(QWidget *w, bool showProgress) : | 52 View::View(QWidget *w, bool showProgress) : |
54 QFrame(w), | 53 QFrame(w), |
55 m_centreFrame(0), | 54 m_centreFrame(0), |
56 m_zoomLevel(1024), | 55 m_zoomLevel(1024), |
363 } | 362 } |
364 | 363 |
365 sv_frame_t | 364 sv_frame_t |
366 View::getFrameForX(int x) const | 365 View::getFrameForX(int x) const |
367 { | 366 { |
368 int z = m_zoomLevel; | 367 sv_frame_t z = m_zoomLevel; // nb not just int, or multiplication may overflow |
369 sv_frame_t frame = m_centreFrame - (width()/2) * z; | 368 sv_frame_t frame = m_centreFrame - (width()/2) * z; |
370 | 369 |
370 frame = (frame / z) * z; // this is start frame | |
371 frame = frame + x * z; | |
372 | |
371 #ifdef DEBUG_VIEW_WIDGET_PAINT | 373 #ifdef DEBUG_VIEW_WIDGET_PAINT |
372 SVDEBUG << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; | 374 cerr << "View::getFrameForX(" << x << "): z = " << z << ", m_centreFrame = " << m_centreFrame << ", width() = " << width() << ", frame = " << frame << endl; |
373 #endif | 375 #endif |
374 | 376 |
375 frame = (frame / z) * z; // this is start frame | 377 return frame; |
376 return frame + x * z; | |
377 } | 378 } |
378 | 379 |
379 double | 380 double |
380 View::getYForFrequency(double frequency, | 381 View::getYForFrequency(double frequency, |
381 double minf, | 382 double minf, |