From 1883ee0c67f3e5f7807f7a886333360e31f804be Mon Sep 17 00:00:00 2001 From: girst Date: Thu, 19 May 2022 15:16:03 +0200 Subject: [PATCH] fix find-following 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(). --- sol.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sol.c b/sol.c index eb382f7..0b687f4 100644 --- a/sol.c +++ b/sol.c @@ -189,6 +189,7 @@ void quit(void) { ((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; @@ -279,7 +280,7 @@ int hls(card_t card, char* hi) { 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; -- 2.39.3