Fix a harmless valgrind warning in RegExpObject
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>
Fri, 9 Jan 2015 17:53:37 +0000 (18:53 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Tue, 13 Jan 2015 11:41:48 +0000 (12:41 +0100)
Only even values are initialized by the RegExp engine and the
compiler might reorder end to be tested before start, which would
let valgrind complain about branching on an uninitialized value.

Fix the issue by only checking if start is offsetNoMatch since it is
implied in the implementation that start == -1 => end == -1.
This matches the behavior of RegExpMatchesArray::reifyAllProperties in WebKit

Change-Id: Ifde1c5bc99da2a7929cd096bf477cae8799e4fed
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/jsruntime/qv4regexpobject.cpp

index 31dd6af..4a843d8 100644 (file)
@@ -387,7 +387,7 @@ ReturnedValue RegExpPrototype::method_exec(CallContext *ctx)
     for (int i = 0; i < len; ++i) {
         int start = matchOffsets[i * 2];
         int end = matchOffsets[i * 2 + 1];
-        v = (start != -1 && end != -1) ? ctx->d()->engine->newString(s.mid(start, end - start))->asReturnedValue() : Encode::undefined();
+        v = (start != -1) ? ctx->d()->engine->newString(s.mid(start, end - start))->asReturnedValue() : Encode::undefined();
         array->arrayPut(i, v);
     }
     array->setArrayLengthUnchecked(len);