From 30f12dfc1f32688f377913c52b131aa78d7830b5 Mon Sep 17 00:00:00 2001 From: Preston Pan Date: Fri, 6 Jan 2023 11:14:52 -0800 Subject: fixed stack bug; found recursion bug --- src/stack.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/stack.c') diff --git a/src/stack.c b/src/stack.c index 2438792..ebfa640 100644 --- a/src/stack.c +++ b/src/stack.c @@ -26,7 +26,7 @@ void stack_push(stack_t *s, hash_table_t *h) { } /* fix heap buffer overflow */ hash_table_t *stack_peek(stack_t *s) { - if (s->cur == -1) + if (is_empty(s)) return NULL; return s->stack[s->cur]; } @@ -37,3 +37,9 @@ hash_table_t *stack_pop(stack_t *s) { s->cur--; return h; } + +bool is_empty(stack_t *s) { + if (s->cur == -1) + return true; + return false; +} -- cgit