diff options
author | Erik Verbruggen <erik.verbruggen@qt.io> | 2017-10-11 11:29:21 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2017-10-23 06:27:44 +0000 |
commit | 2a8d1f27df08aa42fae3d9b80abc4a7935d3ba63 (patch) | |
tree | 3308d84e1a37a314451f090e5292d9156e8edce5 /src/qml/compiler/qv4codegen.cpp | |
parent | 03a1c56714476957a2f3358cf223258e884f8957 (diff) |
Fix potential crash in codegen
Do more checking for previous errors: evaluating a condition can
return an invalid result, because it might bail out because of an error.
Change-Id: I14709e48f00146baac9599320e436abb30acc938
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/qml/compiler/qv4codegen.cpp')
-rw-r--r-- | src/qml/compiler/qv4codegen.cpp | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/src/qml/compiler/qv4codegen.cpp b/src/qml/compiler/qv4codegen.cpp index 824cb77e7a..eac107fc16 100644 --- a/src/qml/compiler/qv4codegen.cpp +++ b/src/qml/compiler/qv4codegen.cpp @@ -321,21 +321,30 @@ void Codegen::statement(ExpressionNode *ast) void Codegen::condition(ExpressionNode *ast, const BytecodeGenerator::Label *iftrue, const BytecodeGenerator::Label *iffalse, bool trueBlockFollowsCondition) { - if (ast) { - Result r(iftrue, iffalse, trueBlockFollowsCondition); - qSwap(_expr, r); - accept(ast); - qSwap(_expr, r); - if (r.format() == ex) { - Q_ASSERT(iftrue == r.iftrue()); - Q_ASSERT(iffalse == r.iffalse()); - bytecodeGenerator->setLocation(ast->firstSourceLocation()); - r.result().loadInAccumulator(); - if (r.trueBlockFollowsCondition()) - bytecodeGenerator->jumpFalse().link(*r.iffalse()); - else - bytecodeGenerator->jumpTrue().link(*r.iftrue()); - } + if (hasError) + return; + + if (!ast) + return; + + Result r(iftrue, iffalse, trueBlockFollowsCondition); + qSwap(_expr, r); + accept(ast); + qSwap(_expr, r); + + if (hasError) + return; + + if (r.format() == ex) { + Q_ASSERT(iftrue == r.iftrue()); + Q_ASSERT(iffalse == r.iffalse()); + Q_ASSERT(r.result().isValid()); + bytecodeGenerator->setLocation(ast->firstSourceLocation()); + r.result().loadInAccumulator(); + if (r.trueBlockFollowsCondition()) + bytecodeGenerator->jumpFalse().link(*r.iffalse()); + else + bytecodeGenerator->jumpTrue().link(*r.iftrue()); } } |