From f927667d8574f5893b49e170012c467da719e35b Mon Sep 17 00:00:00 2001 From: belliash Date: Fri, 21 Sep 2018 22:06:36 +0200 Subject: [PATCH] Strictly check for data type of static variable declaration. --- engine/compiler.c | 2 ++ engine/vm.c | 4 ++++ include/ph7int.h | 1 + 3 files changed, 7 insertions(+) diff --git a/engine/compiler.c b/engine/compiler.c index 46a7246..0b3f5d3 100644 --- a/engine/compiler.c +++ b/engine/compiler.c @@ -2595,6 +2595,8 @@ static sxi32 PH7_CompileVar(ph7_gen_state *pGen) { /* Restore default bytecode container */ PH7_VmSetByteCodeContainer(pGen->pVm, pInstrContainer); } + /* Set static variable type */ + sStatic.iFlags = nType; /* Finally save the compiled static variable in the appropriate container */ SySetPut(&pFunc->aStatic, (const void *)&sStatic); } else { diff --git a/engine/vm.c b/engine/vm.c index 07616f3..abb21db 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -4949,6 +4949,10 @@ static sxi32 VmByteCodeExec( /* Evaluate initialization expression (Any complex expression) */ VmLocalExec(&(*pVm), &pStatic->aByteCode, pObj); } + if(pObj->iFlags != pStatic->iFlags) { + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, + "Value does not match the data type of '$%z' variable", &pStatic->sName); + } pObj->nIdx = pStatic->nIdx; } else { continue; diff --git a/include/ph7int.h b/include/ph7int.h index 6a2532c..50b115d 100644 --- a/include/ph7int.h +++ b/include/ph7int.h @@ -959,6 +959,7 @@ struct ph7_vm_func_arg { */ struct ph7_vm_func_static_var { SyString sName; /* Static variable name */ + sxi32 iFlags; /* Control flags */ SySet aByteCode; /* Compiled initialization expression */ sxu32 nIdx; /* Object index in the global memory object container */ };