aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp1
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp17
2 files changed, 18 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index 85d06bcabe..6a242ba5f6 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1942,6 +1942,7 @@ ReturnedValue Runtime::method_div(const Value &left, const Value &right)
int lval = left.integerValue();
int rval = right.integerValue();
if (rval != 0 // division by zero should result in a NaN
+ && !(lval == std::numeric_limits<int>::min() && rval == -1) // doesn't fit in int
&& (lval % rval == 0) // fractions can't be stored in an int
&& !(lval == 0 && rval < 0)) // 0 / -something results in -0.0
return Encode(int(lval / rval));
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index d8784f4855..0e8844d23f 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -366,6 +366,7 @@ private slots:
void tailCallWithArguments();
void deleteSparseInIteration();
void saveAccumulatorBeforeToInt32();
+ void intMinDividedByMinusOne();
private:
// static void propertyVarWeakRefCallback(v8::Persistent<v8::Value> object, void* parameter);
@@ -8941,6 +8942,22 @@ void tst_qqmlecmascript::saveAccumulatorBeforeToInt32()
QCOMPARE(value.toString(), QLatin1String("RangeError: Maximum call stack size exceeded."));
}
+void tst_qqmlecmascript::intMinDividedByMinusOne()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine);
+ component.setData(QByteArray("import QtQml 2.2\n"
+ "QtObject {\n"
+ " property int intMin: -2147483648\n"
+ " property int minusOne: -1\n"
+ " property double doesNotFitInInt: intMin / minusOne\n"
+ "}"), QUrl());
+ QVERIFY(component.isReady());
+ QScopedPointer<QObject> object(component.create());
+ QVERIFY(!object.isNull());
+ QCOMPARE(object->property("doesNotFitInInt").toUInt(), 2147483648u);
+}
+
QTEST_MAIN(tst_qqmlecmascript)
#include "tst_qqmlecmascript.moc"