From d72506cf985e86610ad3b2dd88bbde8be6dc2428 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sun, 1 Oct 2006 20:55:41 +0000 Subject: Solitaire: Fixed incorrect condition check that caused an out-of-bounds access allowing to put the 2 of spades into nirvana. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11104 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/solitaire.c | 53 ++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/apps/plugins/solitaire.c b/apps/plugins/solitaire.c index dd3efdaf05..93533130ea 100644 --- a/apps/plugins/solitaire.c +++ b/apps/plugins/solitaire.c @@ -866,31 +866,40 @@ enum move move_card( int dest_col, int src_card ) } /* if we are on one of the 4 final stacks ... */ else if( dest_col < REM_COL ) - { - /* ... check if we are on an empty stack, that the src is an - * ace and that this is the good final stack */ - if( dest_card == NOT_A_CARD - && deck[src_card].num == 0 - && deck[src_card].suit == dest_col - STACKS_COL ) - { - /* this is a winning combination */ - stacks[dest_col - STACKS_COL] = src_card; - } - /* ... or check if the cards follow one another, have the same - * suit and {that src has no .next element or is from the remains' - * stack} */ - else if( deck[dest_card].suit == deck[src_card].suit - && deck[dest_card].num + 1 == deck[src_card].num - && (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) ) + { + /* ... check if we are on an empty stack... */ + if( dest_card == NOT_A_CARD ) { - /* this is a winning combination */ - deck[dest_card].next = src_card; + /* ... and the src is an ace and this is the correct final stack */ + if( deck[src_card].num == 0 + && deck[src_card].suit == dest_col - STACKS_COL ) + { + /* this is a winning combination */ + stacks[dest_col - STACKS_COL] = src_card; + } + else + { + /* this is not a winning combination */ + return MOVE_NOT_OK; + } } - /* ... or, well that's not good news */ - else + else /* non-empty stack */ { - /* this is not a winning combination */ - return MOVE_NOT_OK; + /* ...check if the cards follow one another, have the same suit and + * {that src has no .next element or is from the remains' stack} */ + if( deck[dest_card].suit == deck[src_card].suit + && deck[dest_card].num + 1 == deck[src_card].num + && (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) ) + { + /* this is a winning combination */ + deck[dest_card].next = src_card; + } + /* ... or, well that's not good news */ + else + { + /* this is not a winning combination */ + return MOVE_NOT_OK; + } } } /* if we are on the remains' stack */ -- cgit v1.2.3