summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@digia.com>2013-05-15 12:34:47 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-15 14:23:38 +0200
commitf8fdc82e88dd4546062ee220712c300a654472b9 (patch)
treeb3d3206ceb9654c2ad289a532fb3452922cbd38c
parent81ce34e3120102f57ae7fd5ec9d4bf4d09dfb77b (diff)
downloadqt4-tools-f8fdc82e88dd4546062ee220712c300a654472b9.tar.gz
Widgets: avoid integer divide by zero in QProgressDialog
Autotest is included. Task-number: QTBUG-31046 Change-Id: Ief7d71b58e7a5416f3659f19445e5d729849b3b6 (cherry picked from commit 69c05bbef47fb9d30d70e594bd5942add8b135fe) Reviewed-by: J-P Nurmi <jpnurmi@digia.com> Reviewed-by: Liang Qi <liang.qi@digia.com>
-rw-r--r--src/gui/dialogs/qprogressdialog.cpp1
-rw-r--r--tests/auto/qprogressdialog/tst_qprogressdialog.cpp18
2 files changed, 19 insertions, 0 deletions
diff --git a/src/gui/dialogs/qprogressdialog.cpp b/src/gui/dialogs/qprogressdialog.cpp
index 43bce7d7b6..9bab29a2d5 100644
--- a/src/gui/dialogs/qprogressdialog.cpp
+++ b/src/gui/dialogs/qprogressdialog.cpp
@@ -693,6 +693,7 @@ void QProgressDialog::setValue(int progress)
int estimate;
int totalSteps = maximum() - minimum();
int myprogress = progress - minimum();
+ if (myprogress == 0) myprogress = 1;
if ((totalSteps - myprogress) >= INT_MAX / elapsed)
estimate = (totalSteps - myprogress) / myprogress * elapsed;
else
diff --git a/tests/auto/qprogressdialog/tst_qprogressdialog.cpp b/tests/auto/qprogressdialog/tst_qprogressdialog.cpp
index 953ef4843a..459a38e35e 100644
--- a/tests/auto/qprogressdialog/tst_qprogressdialog.cpp
+++ b/tests/auto/qprogressdialog/tst_qprogressdialog.cpp
@@ -46,11 +46,19 @@
#include <qdebug.h>
#include <qprogressdialog.h>
#include <qlabel.h>
+#include <qthread.h>
//TESTED_CLASS=
//TESTED_FILES=
+class TestThread : QThread {
+public:
+ TestThread(unsigned long msecs) {
+ QThread::msleep(msecs);
+ }
+};
+
class tst_QProgressDialog : public QObject
{
Q_OBJECT
@@ -62,6 +70,7 @@ public:
private slots:
void getSetCheck();
void task198202();
+ void QTBUG_31046();
};
tst_QProgressDialog::tst_QProgressDialog()
@@ -153,5 +162,14 @@ void tst_QProgressDialog::task198202()
QCOMPARE(dlg.sizeHint().height(), futureHeight);
}
+void tst_QProgressDialog::QTBUG_31046()
+{
+ QProgressDialog dlg("", "", 50, 60);
+ dlg.setValue(0);
+ TestThread(200);
+ dlg.setValue(50);
+ QCOMPARE(50, dlg.value());
+}
+
QTEST_MAIN(tst_QProgressDialog)
#include "tst_qprogressdialog.moc"