Fix crash in qqmlecmascript::sequenceSort with MSVC in debug builds
authorSimon Hausmann <simon.hausmann@digia.com>
Wed, 26 Jun 2013 10:44:56 +0000 (12:44 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 26 Jun 2013 13:45:59 +0000 (15:45 +0200)
ArrayPrototype.sort allows specifying a compare function implemented in JS,
which we "wrap" and then pass on to std::sort. std::sort with MSVC has
an assertion verifying that the less-than compare function provided is
perfectly consistent in its return values. We don't want JS to easily crash
the entire application and therefore resort to qSort().

Change-Id: Id2c758a7d2bee60f31a7a3971172bca9b3c69af6
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/qml/v4/qv4object.cpp

index fa8813b..1849cc8 100644 (file)
@@ -1166,7 +1166,13 @@ void Object::arraySort(ExecutionContext *context, Object *thisObject, const Valu
     ArrayElementLessThan lessThan(context, thisObject, comparefn);
 
     Property *begin = arrayData;
-    std::sort(begin, begin + len, lessThan);
+    // We deliberately choose qSort over std::sort here, because with
+    // MSVC in debug builds, std::sort has an ASSERT() that verifies
+    // that the return values of lessThan are perfectly consistent
+    // and aborts otherwise. We do not want JavaScript to easily crash
+    // the entire application and therefore choose qSort, which doesn't
+    // have this property.
+    qSort(begin, begin + len, lessThan);
 }