Fix out of bounds errors in Machine.Pop
This commit is contained in:
parent
b4bd86ad1d
commit
850de8a2bf
@ -224,6 +224,10 @@ func (machine *Machine) Push(word int) {
|
||||
// Pop pops the last word off of the stack, and returns it, decreasing the stack
|
||||
// pointer and reallocating the stack if necessary.
|
||||
func (machine *Machine) Pop() (word int) {
|
||||
if machine.pointer <= 0 || machine.pointer >= len(machine.stack) {
|
||||
return
|
||||
}
|
||||
|
||||
word = machine.stack[machine.pointer]
|
||||
machine.pointer--
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user