diff options
author | Preston Pan <preston@nullring.xyz> | 2023-01-06 11:14:52 -0800 |
---|---|---|
committer | Preston Pan <preston@nullring.xyz> | 2023-01-06 11:14:52 -0800 |
commit | 30f12dfc1f32688f377913c52b131aa78d7830b5 (patch) | |
tree | b59a2822cb6edb062b9965e6dc89b718d65b596b /src/stack.c | |
parent | e98f89c84ec0492a36e364ac32987e17296b33df (diff) |
fixed stack bug; found recursion bug
Diffstat (limited to 'src/stack.c')
-rw-r--r-- | src/stack.c | 8 |
1 files changed, 7 insertions, 1 deletions
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; +} |