From 63cda1c13db257995853565ad85a240f63589e86 Mon Sep 17 00:00:00 2001 From: Chronos Ouroboros Date: Tue, 14 Aug 2018 23:08:09 -0300 Subject: [PATCH] Pointer addition opcodes must leave NULL pointers as they are. --- src/scripting/vm/jit.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/scripting/vm/jit.cpp b/src/scripting/vm/jit.cpp index d9af0a7dc..e2bb3178b 100644 --- a/src/scripting/vm/jit.cpp +++ b/src/scripting/vm/jit.cpp @@ -1461,18 +1461,38 @@ JitFuncPtr JitCompile(VMScriptFunction *sfunc) case OP_ADDA_RR: // pA = pB + dkC { auto tmp = cc.newIntPtr(); + Label label = cc.newLabel(); + cc.mov(tmp, regA[B]); + + // Check if zero, the first operand is zero, if it is, don't add. + cc.cmp(tmp, 0); + cc.je(label); + cc.add(tmp, regD[C]); + + cc.bind(label); cc.mov(regA[a], tmp); + break; } case OP_ADDA_RK: { auto tmp = cc.newIntPtr(); + Label label = cc.newLabel(); + cc.mov(tmp, regA[B]); + + // Check if zero, the first operand is zero, if it is, don't add. + cc.cmp(tmp, 0); + cc.je(label); + cc.add(tmp, konstd[C]); + + cc.bind(label); cc.mov(regA[a], tmp); + break; }