Avoid dereferencing NULL pointers.

This commit is contained in:
Murilo Pereira 2011-02-12 01:26:03 -02:00
parent 97c69bdcba
commit 60641ca499
4 changed files with 23 additions and 17 deletions

View File

@ -26,7 +26,9 @@ void initialize_card(struct card *card) {
} }
void delete_card(struct card *card) { void delete_card(struct card *card) {
delete_frame(card->frame); if (card) {
delete_frame(card->frame);
}
free(card); free(card);
return; return;

View File

@ -51,22 +51,22 @@ void initialize_deck(struct deck *deck) {
} }
void delete_deck(struct deck *deck) { void delete_deck(struct deck *deck) {
delete_stack(deck->stock); if (deck) {
delete_stack(deck->waste_pile); delete_stack(deck->waste_pile);
delete_stack(deck->foundation_0); delete_stack(deck->foundation_0);
delete_stack(deck->foundation_1); delete_stack(deck->foundation_1);
delete_stack(deck->foundation_2); delete_stack(deck->foundation_2);
delete_stack(deck->foundation_3); delete_stack(deck->foundation_3);
delete_stack(deck->maneuvre_0);
delete_stack(deck->maneuvre_1);
delete_stack(deck->maneuvre_2);
delete_stack(deck->maneuvre_3);
delete_stack(deck->maneuvre_4);
delete_stack(deck->maneuvre_5);
delete_stack(deck->maneuvre_6);
delete_stack(deck->maneuvre_0);
delete_stack(deck->maneuvre_1);
delete_stack(deck->maneuvre_2);
delete_stack(deck->maneuvre_3);
delete_stack(deck->maneuvre_4);
delete_stack(deck->maneuvre_5);
delete_stack(deck->maneuvre_6);
}
free(deck); free(deck);
return; return;

View File

@ -23,7 +23,9 @@ void initialize_frame(struct frame *frame) {
} }
void delete_frame(struct frame *frame) { void delete_frame(struct frame *frame) {
delwin(frame->shape); if (frame) {
delwin(frame->shape);
}
free(frame); free(frame);
return; return;

View File

@ -29,7 +29,9 @@ void initialize_stack(struct stack *stack) {
} }
void delete_stack(struct stack *stack) { void delete_stack(struct stack *stack) {
delete_card(stack->card); if (stack) {
delete_card(stack->card);
}
free(stack); free(stack);
return; return;