From b97671a3b40623c1499c13c3d74c896ac6b9406f Mon Sep 17 00:00:00 2001 From: makuukka Date: Fri, 29 May 2009 10:08:27 +0300 Subject: Force qRound64() to take a double on platforms where qreal is a float. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Symbian qreal is defined as float. And in qround64 the parameter was qreal. This qround64 is used (only) in qvariant::convert, when converting from double to e.g. int. This caused overflow bug for some (close to max int) values, because in convert chain double value was casted to float. Task-number: 250267 Reviewed-By: Samuel Rødal Reviewed-By: Jason Barron --- src/corelib/global/qglobal.h | 5 +++++ tests/auto/qvariant/tst_qvariant.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 27aaac1..b075db6 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -1055,8 +1055,13 @@ inline T qAbs(const T &t) { return t >= 0 ? t : -t; } inline int qRound(qreal d) { return d >= 0.0 ? int(d + 0.5) : int(d - int(d-1) + 0.5) + int(d-1); } +#if defined(QT_NO_FPU) || defined(QT_ARCH_ARM) || defined(QT_ARCH_WINDOWSCE) || defined(QT_ARCH_SYMBIAN) +inline qint64 qRound64(double d) +{ return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); } +#else inline qint64 qRound64(qreal d) { return d >= 0.0 ? qint64(d + 0.5) : qint64(d - qint64(d-1) + 0.5) + qint64(d-1); } +#endif template inline const T &qMin(const T &a, const T &b) { if (a < b) return a; return b; } diff --git a/tests/auto/qvariant/tst_qvariant.cpp b/tests/auto/qvariant/tst_qvariant.cpp index d15f9c8..9c9ff33 100644 --- a/tests/auto/qvariant/tst_qvariant.cpp +++ b/tests/auto/qvariant/tst_qvariant.cpp @@ -255,6 +255,7 @@ private slots: void convertByteArrayToBool() const; void convertByteArrayToBool_data() const; void toIntFromQString() const; + void toIntFromDouble() const; }; Q_DECLARE_METATYPE(QDate) @@ -2909,5 +2910,30 @@ void tst_QVariant::toIntFromQString() const QVERIFY(ok); } +/*! + We verify that: + 1. Conversion from (64 bit) double to int works (no overflow). + 2. Same conversion works for QVariant::convert. + + Rationale: if 2147483630 is set in float and then converted to int, + there will be overflow and the result will be -2147483648. + + See task 250267. + */ +void tst_QVariant::toIntFromDouble() const +{ + double d = 2147483630; // max int 2147483647 + QVERIFY((int)d == 2147483630); + + QVariant var(d); + QVERIFY( var.canConvert( QVariant::Int ) ); + + bool ok; + int result = var.toInt(&ok); + + QVERIFY( ok == true ); + QCOMPARE(result, 2147483630); +} + QTEST_MAIN(tst_QVariant) #include "tst_qvariant.moc" -- cgit v0.12 From 9108392448f4906bbd6916dcb0bc8117171c7804 Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 10 Jun 2009 10:02:44 +0300 Subject: Added proper UID3 for some demos and examples. --- demos/mediaplayer/mediaplayer.pro | 2 ++ examples/draganddrop/delayedencoding/delayedencoding.pro | 2 ++ examples/draganddrop/draggableicons/draggableicons.pro | 2 ++ examples/draganddrop/draggabletext/draggabletext.pro | 2 ++ examples/draganddrop/puzzle/puzzle.pro | 1 + examples/mainwindows/menus/menus.pro | 2 ++ examples/network/securesocketclient/securesocketclient.pro | 2 ++ examples/painting/svggenerator/svggenerator.pro | 2 ++ examples/phonon/capabilities/capabilities.pro | 2 ++ examples/phonon/musicplayer/musicplayer.pro | 1 + 10 files changed, 18 insertions(+) diff --git a/demos/mediaplayer/mediaplayer.pro b/demos/mediaplayer/mediaplayer.pro index 001989d..ef07a3f 100644 --- a/demos/mediaplayer/mediaplayer.pro +++ b/demos/mediaplayer/mediaplayer.pro @@ -26,3 +26,5 @@ DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout } include($$QT_SOURCE_TREE/demos/demobase.pri) + +symbian:TARGET.UID3 = 0xA000C613 \ No newline at end of file diff --git a/examples/draganddrop/delayedencoding/delayedencoding.pro b/examples/draganddrop/delayedencoding/delayedencoding.pro index c7b95b6..7315ac5 100644 --- a/examples/draganddrop/delayedencoding/delayedencoding.pro +++ b/examples/draganddrop/delayedencoding/delayedencoding.pro @@ -12,3 +12,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/delayedencoding sources.files = $$SOURCES $$HEADERS *.pro sources.path = $$[QT_INSTALL_EXAMPLES]/itemviews/delayedencoding INSTALLS += target sources + +symbian:TARGET.UID3 = 0xA000C614 \ No newline at end of file diff --git a/examples/draganddrop/draggableicons/draggableicons.pro b/examples/draganddrop/draggableicons/draggableicons.pro index 5212abc..6d53baa 100644 --- a/examples/draganddrop/draggableicons/draggableicons.pro +++ b/examples/draganddrop/draggableicons/draggableicons.pro @@ -10,3 +10,5 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggableicons INSTALLS += target sources include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000C615 \ No newline at end of file diff --git a/examples/draganddrop/draggabletext/draggabletext.pro b/examples/draganddrop/draggabletext/draggabletext.pro index 109be5d..15d909d 100644 --- a/examples/draganddrop/draggabletext/draggabletext.pro +++ b/examples/draganddrop/draggabletext/draggabletext.pro @@ -12,3 +12,5 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/draganddrop/draggabletext INSTALLS += target sources include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000CF64 \ No newline at end of file diff --git a/examples/draganddrop/puzzle/puzzle.pro b/examples/draganddrop/puzzle/puzzle.pro index e51eb78..ecaf706 100644 --- a/examples/draganddrop/puzzle/puzzle.pro +++ b/examples/draganddrop/puzzle/puzzle.pro @@ -19,6 +19,7 @@ symbian:{ addFile.sources = example.jpg addFile.path = . DEPLOYMENT += addFile + TARGET.UID3 = 0xA000CF65 } wince*: { addFile.sources = example.jpg diff --git a/examples/mainwindows/menus/menus.pro b/examples/mainwindows/menus/menus.pro index 448e779..8cf60bf 100644 --- a/examples/mainwindows/menus/menus.pro +++ b/examples/mainwindows/menus/menus.pro @@ -9,3 +9,5 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/mainwindows/menus INSTALLS += target sources include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000CF66 \ No newline at end of file diff --git a/examples/network/securesocketclient/securesocketclient.pro b/examples/network/securesocketclient/securesocketclient.pro index 166d7ad..2e9141d 100644 --- a/examples/network/securesocketclient/securesocketclient.pro +++ b/examples/network/securesocketclient/securesocketclient.pro @@ -16,3 +16,5 @@ sources.path = $$[QT_INSTALL_EXAMPLES]/network/securesocketclient INSTALLS += target sources include($$QT_SOURCE_TREE/examples/examplebase.pri) + +symbian:TARGET.UID3 = 0xA000CF67 \ No newline at end of file diff --git a/examples/painting/svggenerator/svggenerator.pro b/examples/painting/svggenerator/svggenerator.pro index 4d08ba4..1134619 100644 --- a/examples/painting/svggenerator/svggenerator.pro +++ b/examples/painting/svggenerator/svggenerator.pro @@ -13,3 +13,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/painting/svggenerator sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS svggenerator.pro sources.path = $$[QT_INSTALL_EXAMPLES]/painting/svggenerator INSTALLS += target sources + +symbian:TARGET.UID3 = 0xA000CF68 \ No newline at end of file diff --git a/examples/phonon/capabilities/capabilities.pro b/examples/phonon/capabilities/capabilities.pro index 29d7501..7f1ca76 100644 --- a/examples/phonon/capabilities/capabilities.pro +++ b/examples/phonon/capabilities/capabilities.pro @@ -9,3 +9,5 @@ target.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities sources.files = $$SOURCES $$HEADERS capabilities.pro sources.path = $$[QT_INSTALL_EXAMPLES]/phonon/capabilities INSTALLS += target sources + +symbian:TARGET.UID3 = 0xA000CF69 \ No newline at end of file diff --git a/examples/phonon/musicplayer/musicplayer.pro b/examples/phonon/musicplayer/musicplayer.pro index 0a93dc2..e17d29c 100644 --- a/examples/phonon/musicplayer/musicplayer.pro +++ b/examples/phonon/musicplayer/musicplayer.pro @@ -14,3 +14,4 @@ wince*{ DEPLOYMENT_PLUGIN += phonon_ds9 phonon_waveout } +symbian:TARGET.UID3 = 0xA000CF6A \ No newline at end of file -- cgit v0.12