diff --git a/engine/vm.c b/engine/vm.c index 7a1c7ea..76e0dbc 100644 --- a/engine/vm.c +++ b/engine/vm.c @@ -2936,6 +2936,7 @@ static sxi32 VmByteCodeExec( */ case PH7_OP_MUL: case PH7_OP_MUL_STORE: { + SyString sName; ph7_value *pNos = &pTos[-1]; /* Force the operand to be numeric */ if(pNos < pStack) { @@ -2974,7 +2975,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - PH7_MemObjStore(pNos, pObj); + if(PH7_MemObjSafeStore(pNos, pObj) != SXRET_OK) { + SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); + }; } } VmPopOperand(&pTos, 1); @@ -3027,11 +3031,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - if(pNos->nType != pObj->nType && PH7_CheckVarCompat(pNos, pObj->nType) != SXRET_OK) { + if(PH7_MemObjSafeStore(pNos, pObj) != SXRET_OK) { SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); }; - PH7_MemObjStore(pNos, pObj); } } VmPopOperand(&pTos, 1); @@ -3084,6 +3087,7 @@ static sxi32 VmByteCodeExec( * and push the result back onto the stack. */ case PH7_OP_ADD_STORE: { + SyString sName; ph7_value *pNos = &pTos[-1]; ph7_value *pObj; if(pNos < pStack) { @@ -3107,7 +3111,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - PH7_MemObjStore(pTos, pObj); + if(PH7_MemObjSafeStore(pTos, pObj) != SXRET_OK) { + SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); + }; } /* Ticket 1433-35: Perform a stack dup */ PH7_MemObjStore(pTos, pNos); @@ -3160,6 +3167,7 @@ static sxi32 VmByteCodeExec( * top of the stack) and push the result back onto the stack. */ case PH7_OP_SUB_STORE: { + SyString sName; ph7_value *pNos = &pTos[-1]; ph7_value *pObj; if(pNos < pStack) { @@ -3193,7 +3201,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - PH7_MemObjStore(pNos, pObj); + if(PH7_MemObjSafeStore(pNos, pObj) != SXRET_OK) { + SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); + }; } VmPopOperand(&pTos, 1); break; @@ -3245,6 +3256,7 @@ static sxi32 VmByteCodeExec( * Note: Only integer arithemtic is allowed. */ case PH7_OP_MOD_STORE: { + SyString sName; ph7_value *pNos = &pTos[-1]; ph7_value *pObj; sxi64 a, b, r; @@ -3273,7 +3285,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - PH7_MemObjStore(pNos, pObj); + if(PH7_MemObjSafeStore(pNos, pObj) != SXRET_OK) { + SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); + }; } VmPopOperand(&pTos, 1); break; @@ -3322,6 +3337,7 @@ static sxi32 VmByteCodeExec( * Note: Only floating point arithemtic is allowed. */ case PH7_OP_DIV_STORE: { + SyString sName; ph7_value *pNos = &pTos[-1]; ph7_value *pObj; ph7_real a, b, r; @@ -3350,7 +3366,10 @@ static sxi32 VmByteCodeExec( if(pTos->nIdx == SXU32_HIGH) { PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot perform assignment on a constant class attribute"); } else if((pObj = (ph7_value *)SySetAt(&pVm->aMemObj, pTos->nIdx)) != 0) { - PH7_MemObjStore(pNos, pObj); + if(PH7_MemObjSafeStore(pNos, pObj) != SXRET_OK) { + SyStringInitFromBuf(&sName, pInstr->p3, SyStrlen((const char *)pInstr->p3)); + PH7_VmThrowError(&(*pVm), PH7_CTX_ERR, "Cannot assign a value of incompatible type to variable '$%z'", &sName); + }; } VmPopOperand(&pTos, 1); break;