diff --git a/vm/vm.cpp b/vm/vm.cpp index aa7a0f1..4ef3f11 100644 --- a/vm/vm.cpp +++ b/vm/vm.cpp @@ -602,23 +602,25 @@ bool VM::execSHRR(void) { return true; } bool VM::execPUSH(void) { - // TODO: STACK < 0 uint8_t src; src = as.code[regs[IP] + 1]; DBG_INFO(("PUSH %s\n", getRegName(src))); + if (regs[SP] + sizeof(uint16_t) > 0xffff) { + DBG_ERROR(("Out of bound: stack is going above 0xFFFF!\n")); + return false; + } memcpy(&as.stack[regs[SP]], ®s[src], sizeof(uint16_t)); regs[SP] += sizeof(uint16_t); return true; } bool VM::execPOOP(void) { - // TODO: STACK < 0 uint8_t dst; dst = as.code[regs[IP] + 1]; DBG_INFO(("POOP %s\n", getRegName(dst))); if (regs[SP] - sizeof(uint16_t) < 0) { - DBG_ERROR(("Stack is going below 0!\n")); + DBG_ERROR(("Out of bound: stack is going below 0!\n")); return false; } regs[SP] -= sizeof(uint16_t);