From 6b18e204cd5293d7d2715e490921eab4d2a4bc47 Mon Sep 17 00:00:00 2001 From: Piotr Likoski Date: Tue, 16 Apr 2019 20:15:38 +0200 Subject: [PATCH] Always pop the l-value on variable declaration. Otherwise, it might lead to unexpected behaviour including protected memory access and segmentation fault. This finally fixes #49. --- engine/compiler.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/engine/compiler.c b/engine/compiler.c index 5827b7d..598e2b8 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -2555,6 +2555,8 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen) { void *p3 = (void *) zDup; /* Emit OP_DECLARE instruction */ PH7_VmEmitInstr(pGen->pVm, pGen->pIn->nLine, PH7_OP_DECLARE, 0, nType, p3, 0); + /* Pop the l-value */ + PH7_VmEmitInstr(pGen->pVm, nLine, PH7_OP_POP, 1, 0, 0, 0); /* Check if we have an expression to compile */ if(pGen->pIn < pGen->pEnd && (pGen->pIn[2].nType & PH7_TK_EQUAL)) { /* Compile the expression */