diff options
author | Jens Arnold <amiconn@rockbox.org> | 2006-10-01 20:55:41 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2006-10-01 20:55:41 +0000 |
commit | d72506cf985e86610ad3b2dd88bbde8be6dc2428 (patch) | |
tree | a467909b5c4f88ce72188cc85e7fce6dd9de935c | |
parent | f3fc9cbd8b66ad97ff5be78c8adc9e7aeccdc328 (diff) | |
download | rockbox-d72506cf985e86610ad3b2dd88bbde8be6dc2428.tar.gz rockbox-d72506cf985e86610ad3b2dd88bbde8be6dc2428.zip |
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
-rw-r--r-- | apps/plugins/solitaire.c | 53 |
1 files 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 ) | |||
866 | } | 866 | } |
867 | /* if we are on one of the 4 final stacks ... */ | 867 | /* if we are on one of the 4 final stacks ... */ |
868 | else if( dest_col < REM_COL ) | 868 | else if( dest_col < REM_COL ) |
869 | { | 869 | { |
870 | /* ... check if we are on an empty stack, that the src is an | 870 | /* ... check if we are on an empty stack... */ |
871 | * ace and that this is the good final stack */ | 871 | if( dest_card == NOT_A_CARD ) |
872 | if( dest_card == NOT_A_CARD | ||
873 | && deck[src_card].num == 0 | ||
874 | && deck[src_card].suit == dest_col - STACKS_COL ) | ||
875 | { | ||
876 | /* this is a winning combination */ | ||
877 | stacks[dest_col - STACKS_COL] = src_card; | ||
878 | } | ||
879 | /* ... or check if the cards follow one another, have the same | ||
880 | * suit and {that src has no .next element or is from the remains' | ||
881 | * stack} */ | ||
882 | else if( deck[dest_card].suit == deck[src_card].suit | ||
883 | && deck[dest_card].num + 1 == deck[src_card].num | ||
884 | && (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) ) | ||
885 | { | 872 | { |
886 | /* this is a winning combination */ | 873 | /* ... and the src is an ace and this is the correct final stack */ |
887 | deck[dest_card].next = src_card; | 874 | if( deck[src_card].num == 0 |
875 | && deck[src_card].suit == dest_col - STACKS_COL ) | ||
876 | { | ||
877 | /* this is a winning combination */ | ||
878 | stacks[dest_col - STACKS_COL] = src_card; | ||
879 | } | ||
880 | else | ||
881 | { | ||
882 | /* this is not a winning combination */ | ||
883 | return MOVE_NOT_OK; | ||
884 | } | ||
888 | } | 885 | } |
889 | /* ... or, well that's not good news */ | 886 | else /* non-empty stack */ |
890 | else | ||
891 | { | 887 | { |
892 | /* this is not a winning combination */ | 888 | /* ...check if the cards follow one another, have the same suit and |
893 | return MOVE_NOT_OK; | 889 | * {that src has no .next element or is from the remains' stack} */ |
890 | if( deck[dest_card].suit == deck[src_card].suit | ||
891 | && deck[dest_card].num + 1 == deck[src_card].num | ||
892 | && (deck[src_card].next == NOT_A_CARD || src_col == REM_COL) ) | ||
893 | { | ||
894 | /* this is a winning combination */ | ||
895 | deck[dest_card].next = src_card; | ||
896 | } | ||
897 | /* ... or, well that's not good news */ | ||
898 | else | ||
899 | { | ||
900 | /* this is not a winning combination */ | ||
901 | return MOVE_NOT_OK; | ||
902 | } | ||
894 | } | 903 | } |
895 | } | 904 | } |
896 | /* if we are on the remains' stack */ | 905 | /* if we are on the remains' stack */ |