diff options
author | dholland <dholland@NetBSD.org> | 2012-10-13 20:36:06 +0000 |
---|---|---|
committer | dholland <dholland@NetBSD.org> | 2012-10-13 20:36:06 +0000 |
commit | 88ff9c0697c57951fd41e8543aacb033ef78a94f (patch) | |
tree | dce2a1f4622a9d00861b042ed93f1b843030f00a /cribbage/score.c | |
parent | d95245bbc4af79f67d7ab65fcd4fa4d6855dc849 (diff) | |
download | bsdgames-darwin-88ff9c0697c57951fd41e8543aacb033ef78a94f.tar.gz bsdgames-darwin-88ff9c0697c57951fd41e8543aacb033ef78a94f.tar.zst bsdgames-darwin-88ff9c0697c57951fd41e8543aacb033ef78a94f.zip |
Pass -Wstrict-overflow, and while here, don't read from index -1 of
an array.
Diffstat (limited to 'cribbage/score.c')
-rw-r--r-- | cribbage/score.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/cribbage/score.c b/cribbage/score.c index 2228c7f3..a2af9eb7 100644 --- a/cribbage/score.c +++ b/cribbage/score.c @@ -1,4 +1,4 @@ -/* $NetBSD: score.c,v 1.15 2009/08/12 05:48:04 dholland Exp $ */ +/* $NetBSD: score.c,v 1.16 2012/10/13 20:36:06 dholland Exp $ */ /*- * Copyright (c) 1980, 1993 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)score.c 8.1 (Berkeley) 5/31/93"; #else -__RCSID("$NetBSD: score.c,v 1.15 2009/08/12 05:48:04 dholland Exp $"); +__RCSID("$NetBSD: score.c,v 1.16 2012/10/13 20:36:06 dholland Exp $"); #endif #endif /* not lint */ @@ -289,11 +289,12 @@ pairuns(const CARD h[], int n) * the n cards in tbl during pegging */ int -pegscore(CARD crd, const CARD tbl[], int n, int sum) +pegscore(CARD crd, const CARD tbl[], unsigned n, int sum) { BOOLEAN got[RANKS]; int i, j, scr; int k, lo, hi; + unsigned ju; sum += VAL(crd.rank); if (sum > 31) @@ -304,11 +305,11 @@ pegscore(CARD crd, const CARD tbl[], int n, int sum) scr = 0; if (!n) return (scr); - j = 1; - while ((crd.rank == tbl[n - j].rank) && (n - j >= 0)) - ++j; - if (j > 1) - return (scr + ichoose2[j]); + ju = 1; + while (ju <= n && crd.rank == tbl[n - ju].rank) + ++ju; + if (ju > 1) + return (scr + ichoose2[ju]); if (n < 2) return (scr); lo = hi = crd.rank; |