Handle invalid function calls

This commit is contained in:
Ian Gulliver
2021-11-19 15:45:51 -10:00
parent 7da1ea96da
commit 534c4fe513
2 changed files with 7 additions and 6 deletions

View File

@@ -71,6 +71,10 @@ func (state *State) processInstruction() {
state.instructionIndex += 1
instr.opHandler(state, instr)
if state.functionIndex >= int64(len(state.functions)) {
state.ret()
}
if state.instructionIndex >= int64(len(fnc)) {
state.ret()
}
@@ -132,11 +136,6 @@ func (state *State) writeSigned(op *Operand, value int64) {
}
func (state *State) call(functionOffset int64) {
if state.functionIndex+functionOffset >= int64(len(state.functions)) {
state.setError(fmt.Errorf("Invalid function call index: %d + %d = %d", state.functionIndex, functionOffset, state.functionIndex+functionOffset))
return
}
stackFrame := newStackFrame(state)
state.stack = append(state.stack, stackFrame)
state.functionIndex += functionOffset