aboutsummaryrefslogtreecommitdiff
path: root/stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'stack.c')
-rw-r--r--stack.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/stack.c b/stack.c
index 1edb5c5..f0624c8 100644
--- a/stack.c
+++ b/stack.c
@@ -18,11 +18,13 @@ int ps_push(PositionStack *ps, Position pos) {
}
Position ps_pop(PositionStack *ps) {
+ if (ps->top == 0) error("Stack underflow\n");
ps->top -= 1;
return ps->arr[ps->top];
}
Position ps_peek(PositionStack ps) {
+ if (ps.top == 0) error("Stack underflow\n");
return ps.arr[ps.top - 1];
}