From 850de8a2bf34fb12969d356488a12cabdff76164 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sun, 28 Aug 2022 18:22:11 -0400 Subject: [PATCH] Fix out of bounds errors in Machine.Pop --- creature.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/creature.go b/creature.go index 5fd8b75..f080a83 100644 --- a/creature.go +++ b/creature.go @@ -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--