QtWidgets: avoid integer divide by zero in QProgressDialog
Autotest is included. Task-number: QTBUG-31046 Change-Id: Ie549b59112f458de478294fa00443a3cf6898c85 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
This commit is contained in:
parent
252cba3cd5
commit
69c05bbef4
@ -662,6 +662,7 @@ void QProgressDialog::setValue(int progress)
|
|||||||
int estimate;
|
int estimate;
|
||||||
int totalSteps = maximum() - minimum();
|
int totalSteps = maximum() - minimum();
|
||||||
int myprogress = progress - minimum();
|
int myprogress = progress - minimum();
|
||||||
|
if (myprogress == 0) myprogress = 1;
|
||||||
if ((totalSteps - myprogress) >= INT_MAX / elapsed)
|
if ((totalSteps - myprogress) >= INT_MAX / elapsed)
|
||||||
estimate = (totalSteps - myprogress) / myprogress * elapsed;
|
estimate = (totalSteps - myprogress) / myprogress * elapsed;
|
||||||
else
|
else
|
||||||
|
@ -46,6 +46,7 @@
|
|||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
#include <qprogressdialog.h>
|
#include <qprogressdialog.h>
|
||||||
#include <qlabel.h>
|
#include <qlabel.h>
|
||||||
|
#include <qthread.h>
|
||||||
|
|
||||||
class tst_QProgressDialog : public QObject
|
class tst_QProgressDialog : public QObject
|
||||||
{
|
{
|
||||||
@ -58,6 +59,7 @@ public:
|
|||||||
private slots:
|
private slots:
|
||||||
void getSetCheck();
|
void getSetCheck();
|
||||||
void task198202();
|
void task198202();
|
||||||
|
void QTBUG_31046();
|
||||||
};
|
};
|
||||||
|
|
||||||
tst_QProgressDialog::tst_QProgressDialog()
|
tst_QProgressDialog::tst_QProgressDialog()
|
||||||
@ -149,5 +151,14 @@ void tst_QProgressDialog::task198202()
|
|||||||
QCOMPARE(dlg.sizeHint().height(), futureHeight);
|
QCOMPARE(dlg.sizeHint().height(), futureHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QProgressDialog::QTBUG_31046()
|
||||||
|
{
|
||||||
|
QProgressDialog dlg("", "", 50, 60);
|
||||||
|
dlg.setValue(0);
|
||||||
|
QThread::msleep(200);
|
||||||
|
dlg.setValue(50);
|
||||||
|
QCOMPARE(50, dlg.value());
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QProgressDialog)
|
QTEST_MAIN(tst_QProgressDialog)
|
||||||
#include "tst_qprogressdialog.moc"
|
#include "tst_qprogressdialog.moc"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user