Browse Source

Always perform type validation when inserting value to an array.

release/v0.1
Rafal Kupiec 2 years ago
parent
commit
a0405f2267
Signed by: belliash GPG Key ID: 4E829243E0CFE6B4
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      engine/vm.c

+ 18
- 1
engine/vm.c View File

@ -2867,8 +2867,25 @@ static sxi32 VmByteCodeExec(
}
pMap = (ph7_hashmap *)pObj->x.pOther;
}
sxu32 pArrType = pTos->iFlags ^ MEMOBJ_HASHMAP;
VmPopOperand(&pTos, 1);
/* Phase#2: Perform the insertion */
/* Phase#2: Perform the type validation */
if((pArrType & MEMOBJ_MIXED) == 0 && (pTos->iFlags & pArrType) == 0) {
sxu32 rc = SXRET_OK;
if(pTos->iFlags & MEMOBJ_HASHMAP) {
rc = PH7_HashmapCast(pTos, pArrType);
} else {
if((rc = PH7_CheckVarCompat(pTos, pArrType)) == SXRET_OK) {
ProcMemObjCast xCast = PH7_MemObjCastMethod(pArrType);
xCast(pTos);
}
}
if(rc != SXRET_OK) {
PH7_VmThrowError(&(*pVm), PH7_CTX_ERR,
"Cannot insert a value of incompatible type to array");
}
}
/* Phase#3: Perform the insertion */
PH7_HashmapInsert(pMap, pKey, pTos);
if(pKey) {
PH7_MemObjRelease(pKey);


Loading…
Cancel
Save