From e72d21f1f080e23c2e3e96567325c49cfee75c82 Mon Sep 17 00:00:00 2001 From: Murilo Soares Pereira Date: Sun, 4 Apr 2010 04:15:43 -0300 Subject: [PATCH] Fixed malloc() and pop(). --- lib/stack.c | 12 ++++++------ lib/stack.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/stack.c b/lib/stack.c index 60a25ca..53d800d 100644 --- a/lib/stack.c +++ b/lib/stack.c @@ -6,7 +6,7 @@ struct stack *initialize_stack() { struct stack *stack = NULL; - stack = malloc(sizeof(stack)); + stack = malloc(sizeof(*stack)); stack->card = NULL; stack->next = NULL; @@ -46,13 +46,13 @@ void push(struct stack **stack, struct card *card) { } } -struct stack *pop(struct stack *stack) { +struct stack *pop(struct stack **stack) { struct stack *popped_entry = NULL; - if(!empty(stack)) { - popped_entry = stack; - popped_entry = NULL; - stack = stack->next; + if(!empty(*stack)) { + popped_entry = *stack; + *stack = (*stack)->next; + popped_entry->next = NULL; } return(popped_entry); diff --git a/lib/stack.h b/lib/stack.h index e1b8f21..6b277e8 100644 --- a/lib/stack.h +++ b/lib/stack.h @@ -10,6 +10,6 @@ struct stack *initialize_stack(); bool empty(struct stack *); int length(struct stack *); void push(struct stack **, struct card *); -struct stack *pop(struct stack *); +struct stack *pop(struct stack **); #endif