this bug manifested in freecell as the ace of clubs not recognized as
placable on the foundation (from the tableu) when all four free cells
were occupied.
due to us not checking that find_top() found a card at all, we
accidentally checked foundation[-1], which is the fourth free cell.
there are probably more bugs stemming from this misuse of find_top().
((get_suit(card) ^ get_suit(card)>>1) & 1)
int find_top(card_t* pile) {
+ // TODO: on use, must check that result != -1
int i;
for(i=PILE_SIZE-1; i>=0 && !pile[i]; i--);
return i;
case 'f': case 'F': { /* highlight cards that go on the foundation next */
card_t* foundation = f.f[get_suit(card)];
int top = find_top(foundation);
- if (foundation[top]) {
+ if (top >= 0 && foundation[top]) {
if (rank_next(foundation[top], card) &&
get_suit(card) == get_suit(foundation[top]))
return 1;