Fix invalid spot's segfaults added with the new code.

This commit is contained in:
Murilo Pereira 2011-06-05 18:41:09 -03:00
parent ff0dd068be
commit 656f8e6190

View File

@ -168,12 +168,16 @@ static void handle_card_movement(struct cursor *cursor) {
if (maneuvre_stack(*origin) && marked_cards > 0) {
erase_stack(*origin);
unmark_cards(*origin);
draw_stack(*origin);
}
if (marked_cards > 1 && maneuvre_stack(*origin) && maneuvre_stack(*destination)) {
if (destination) {
if (marked_cards > 1 &&
maneuvre_stack(*origin) &&
maneuvre_stack(*destination)) {
struct stack *block = *origin;
for (int i = 1; i < marked_cards; block = block->next, i++)
;
if (destination && valid_move(block, *destination)) {
if (valid_move(block, *destination)) {
erase_stack(*origin);
struct stack *tmp;
allocate_stack(&tmp);
@ -189,25 +193,28 @@ static void handle_card_movement(struct cursor *cursor) {
cursor->y += marked_cards;
}
free_stack(tmp);
draw_stack(*origin);
draw_stack(*destination);
}
} else {
if (destination && valid_move(*origin, *destination)) {
if (valid_move(*origin, *destination)) {
erase_stack(*origin);
move_card(origin, destination);
if (maneuvre_stack(*destination) && length(*destination) > 1) {
erase_cursor(cursor);
cursor->y++;
}
draw_stack(*origin);
draw_stack(*destination);
}
}
if (maneuvre_stack(*origin) && destination && *origin == *destination) {
if (maneuvre_stack(*origin) && *origin == *destination) {
erase_cursor(cursor);
cursor->y--;
}
}
unmark_cursor(cursor);
draw_cursor(cursor);
draw_stack(*origin);
draw_stack(*destination);
return;
case KEY_ESCAPE:
if (cursor_stack(cursor) == origin && maneuvre_stack(*origin)) {