Fix failing assertion inside MSVC STL in debug builds
authorSimon Hausmann <simon.hausmann@digia.com>
Tue, 29 Apr 2014 12:45:13 +0000 (14:45 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Wed, 21 May 2014 14:20:35 +0000 (16:20 +0200)
When using FunctionObject's call() method, we use std::copy to copy the
arguments over to the new call context. Unfortunately std::copy has an
assertion in there to check that we're not copying out of bounds.  What the STL
doesn't know is that the Value args[1] array is dynamically allocated and
easily expands beyond just one entry.

Fall back to copying by hand to work around this issue.

Task-number: QTBUG-38195
Change-Id: I6e254b1c893ccf5cad2358179cda1b07b00228e0
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
src/qml/jsruntime/qv4functionobject.cpp

index 8e943fa..39a123c 100644 (file)
@@ -326,8 +326,8 @@ ReturnedValue FunctionPrototype::method_call(CallContext *ctx)
 
     ScopedCallData callData(scope, ctx->callData->argc ? ctx->callData->argc - 1 : 0);
     if (ctx->callData->argc) {
-        std::copy(ctx->callData->args + 1,
-                  ctx->callData->args + ctx->callData->argc, callData->args);
+        for (int i = 1; i < ctx->callData->argc; ++i)
+            callData->args[i - 1] = ctx->callData->args[i];
     }
     callData->thisObject = ctx->argument(0);
     return o->call(callData);