From 3c9c35b648e32082b30786fe71d4db33ffe2b5a6 Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Tue, 26 Nov 2013 12:22:36 +0100 Subject: Prospective fix for crashes when sorting JS arrays on Windows std::sort doesn't seem to like sorting empty arrays, so check the size before sorting. Task-number: QTBUG-33658 Change-Id: I841259939ea3bf850d23c129744c322ed46a95fe Reviewed-by: Erik Verbruggen --- src/qml/jsruntime/qv4object.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/qml/jsruntime/qv4object.cpp b/src/qml/jsruntime/qv4object.cpp index e4df95716d..743d35fa69 100644 --- a/src/qml/jsruntime/qv4object.cpp +++ b/src/qml/jsruntime/qv4object.cpp @@ -1262,13 +1262,9 @@ void Object::arraySort(ExecutionContext *context, ObjectRef thisObject, const Va ArrayElementLessThan lessThan(context, thisObject, comparefn); + if (!len) + return; Property *begin = arrayData; - // 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. std::sort(begin, begin + len, lessThan); } -- cgit v1.2.3