diff --git a/lib/stack.c b/lib/stack.c index 53a9aaa..deba919 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -19,12 +19,14 @@ bool empty(struct stack *stack) { } int length(struct stack *stack) { + struct stack *iterator = stack; int length = 0; if (!empty(stack)) { length = 1; - while (stack->next != NULL) { + while (iterator->next != NULL) { length++; + iterator = iterator->next; } }