From 977fd1e25e8bee47171a9a1b8649888ef56d1ce3 Mon Sep 17 00:00:00 2001 From: losfair Date: Sat, 13 Jul 2019 00:17:33 +0800 Subject: [PATCH] Fix trap offset lookup. --- lib/runtime-core/src/state.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/runtime-core/src/state.rs b/lib/runtime-core/src/state.rs index 72046bf6f..8650cb4ac 100644 --- a/lib/runtime-core/src/state.rs +++ b/lib/runtime-core/src/state.rs @@ -111,7 +111,13 @@ impl ModuleStateMap { .unwrap(); match fsm.call_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } } @@ -132,7 +138,13 @@ impl ModuleStateMap { .unwrap(); match fsm.trappable_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } } @@ -149,7 +161,13 @@ impl ModuleStateMap { .unwrap(); match fsm.loop_offsets.get(&(ip - base)) { - Some(x) => Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))), + Some(x) => { + if x.diff_id < fsm.diffs.len() { + Some((fsm, fsm.diffs[x.diff_id].build_state(fsm))) + } else { + None + } + } None => None, } }