summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-31 18:14:54 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-05-31 18:14:54 +0300
commitff8da0b835e94462e6b5da6fbe48409fdff40b28 (patch)
tree38a9d2e6bb72b06e04944317e61c6e8f3bbcf661 /py/vm.c
parentae9c82d5f39ffb69bf47622ed1e67a6d2f2f66f4 (diff)
downloadmicropython-ff8da0b835e94462e6b5da6fbe48409fdff40b28.tar.gz
micropython-ff8da0b835e94462e6b5da6fbe48409fdff40b28.zip
vm: Detect stack underflow in addition to overflow.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/py/vm.c b/py/vm.c
index c04eb89547..aa7e0e2cfc 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -158,6 +158,13 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode2(code, &ip, &state[n_state - 1], &sp, exc_stack, &exc_sp, MP_OBJ_NULL);
#if DETECT_VM_STACK_OVERFLOW
+ if (vm_return_kind == MP_VM_RETURN_NORMAL) {
+ if (sp != state) {
+ printf("Stack misalign: %d\n", sp - state);
+ assert(0);
+ }
+ }
+
// We can't check the case when an exception is returned in state[n_state - 1]
// and there are no arguments, because in this case our detection slot may have
// been overwritten by the returned exception (which is allowed).