Module Name:    src
Committed By:   dholland
Date:           Sat Oct 13 20:36:07 UTC 2012

Modified Files:
        src/games/cribbage: crib.c cribbage.h io.c score.c

Log Message:
Pass -Wstrict-overflow, and while here, don't read from index -1 of
an array.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/games/cribbage/crib.c
cvs rdiff -u -r1.16 -r1.17 src/games/cribbage/cribbage.h
cvs rdiff -u -r1.26 -r1.27 src/games/cribbage/io.c
cvs rdiff -u -r1.15 -r1.16 src/games/cribbage/score.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/games/cribbage/crib.c
diff -u src/games/cribbage/crib.c:1.24 src/games/cribbage/crib.c:1.25
--- src/games/cribbage/crib.c:1.24	Wed Aug 12 05:48:04 2009
+++ src/games/cribbage/crib.c	Sat Oct 13 20:36:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: crib.c,v 1.24 2009/08/12 05:48:04 dholland Exp $	*/
+/*	$NetBSD: crib.c,v 1.25 2012/10/13 20:36:06 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
 #if 0
 static char sccsid[] = "@(#)crib.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: crib.c,v 1.24 2009/08/12 05:48:04 dholland Exp $");
+__RCSID("$NetBSD: crib.c,v 1.25 2012/10/13 20:36:06 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -460,7 +460,7 @@ prcrib(BOOLEAN mycrib, BOOLEAN blank)
  *	Handle all the pegging...
  */
 static CARD Table[14];
-static int Tcnt;
+static unsigned Tcnt;
 
 static int
 peg(BOOLEAN mycrib)

Index: src/games/cribbage/cribbage.h
diff -u src/games/cribbage/cribbage.h:1.16 src/games/cribbage/cribbage.h:1.17
--- src/games/cribbage/cribbage.h:1.16	Fri Aug 26 06:18:17 2011
+++ src/games/cribbage/cribbage.h	Sat Oct 13 20:36:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: cribbage.h,v 1.16 2011/08/26 06:18:17 dholland Exp $	*/
+/*	$NetBSD: cribbage.h,v 1.17 2012/10/13 20:36:06 dholland Exp $	*/
 
 /*
  * Copyright (c) 1980, 1993
@@ -77,10 +77,10 @@ void	 makeknown(const CARD [], int);
 void	 msg(const char *, ...) __printflike(1, 2);
 int	 msgcard(CARD, BOOLEAN);
 int	 number(int, int, const char *);
-int	 pegscore(CARD, const CARD [], int, int);
+int	 pegscore(CARD, const CARD [], unsigned, int);
 int	 plyrhand(const CARD [], const char *);
 void	 prcard(WINDOW *, int, int, CARD, BOOLEAN);
-void	 prhand(const CARD [], int, WINDOW *, BOOLEAN);
+void	 prhand(const CARD [], unsigned, WINDOW *, BOOLEAN);
 void	 receive_intr(int) __dead;
 int	 scorehand(const CARD [], CARD, int, BOOLEAN, BOOLEAN);
 void	 shuffle(CARD []);

Index: src/games/cribbage/io.c
diff -u src/games/cribbage/io.c:1.26 src/games/cribbage/io.c:1.27
--- src/games/cribbage/io.c:1.26	Mon May 23 22:48:52 2011
+++ src/games/cribbage/io.c	Sat Oct 13 20:36:06 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.26 2011/05/23 22:48:52 joerg Exp $	*/
+/*	$NetBSD: io.c,v 1.27 2012/10/13 20:36:06 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)io.c	8.1 (Berkeley) 5/31/93";
 #else
-__RCSID("$NetBSD: io.c,v 1.26 2011/05/23 22:48:52 joerg Exp $");
+__RCSID("$NetBSD: io.c,v 1.27 2012/10/13 20:36:06 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,7 +59,7 @@ __RCSID("$NetBSD: io.c,v 1.26 2011/05/23
 #define	CTRL(X)			(X - 'A' + 1)
 
 static int msgcrd(CARD, BOOLEAN, const char *, BOOLEAN);
-static void printcard(WINDOW *, int, CARD, BOOLEAN);
+static void printcard(WINDOW *, unsigned, CARD, BOOLEAN);
 static int incard(CARD *);
 static void wait_for(int);
 static int readchar(void);
@@ -121,7 +121,7 @@ msgcrd(CARD c, BOOLEAN brfrank, const ch
  *	Print out a card.
  */
 static void
-printcard(WINDOW *win, int cardno, CARD c, BOOLEAN blank)
+printcard(WINDOW *win, unsigned cardno, CARD c, BOOLEAN blank)
 {
 	prcard(win, cardno * 2, cardno, c, blank);
 }
@@ -154,9 +154,9 @@ prcard(WINDOW *win, int y, int x, CARD c
  *	Print a hand of n cards
  */
 void
-prhand(const CARD h[], int n, WINDOW *win, BOOLEAN blank)
+prhand(const CARD h[], unsigned n, WINDOW *win, BOOLEAN blank)
 {
-	int i;
+	unsigned i;
 
 	werase(win);
 	for (i = 0; i < n; i++)
@@ -519,7 +519,7 @@ over:
 char *
 get_line(void)
 {
-	char *sp;
+	size_t pos;
 	int c, oy, ox;
 	WINDOW *oscr;
 
@@ -528,36 +528,36 @@ get_line(void)
 	getyx(stdscr, oy, ox);
 	refresh();
 	/* loop reading in the string, and put it in a temporary buffer */
-	for (sp = linebuf; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
+	for (pos = 0; (c = readchar()) != '\n'; clrtoeol(), refresh()) {
 			if (c == erasechar()) {	/* process erase character */
-				if (sp > linebuf) {
+				if (pos > 0) {
 					int i;
 
-					sp--;
-					for (i = strlen(unctrl(*sp)); i; i--)
+					pos--;
+					for (i = strlen(unctrl(linebuf[pos])); i; i--)
 						addch('\b');
 				}
 				continue;
 			} else
 				if (c == killchar()) {	/* process kill
 							 * character */
-					sp = linebuf;
+					pos = 0;
 					move(oy, ox);
 					continue;
 				} else
-					if (sp == linebuf && c == ' ')
+					if (pos == 0 && c == ' ')
 						continue;
-		if (sp >= &linebuf[LINESIZE - 1] || !(isprint(c) || c == ' '))
+		if (pos >= LINESIZE - 1 || !(isprint(c) || c == ' '))
 			putchar(CTRL('G'));
 		else {
 			if (islower(c))
 				c = toupper(c);
-			*sp++ = c;
+			linebuf[pos++] = c;
 			addstr(unctrl(c));
 			Mpos++;
 		}
 	}
-	*sp = '\0';
+	linebuf[pos] = '\0';
 	stdscr = oscr;
 	return (linebuf);
 }

Index: src/games/cribbage/score.c
diff -u src/games/cribbage/score.c:1.15 src/games/cribbage/score.c:1.16
--- src/games/cribbage/score.c:1.15	Wed Aug 12 05:48:04 2009
+++ src/games/cribbage/score.c	Sat Oct 13 20:36:06 2012
@@ -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
 		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;

Reply via email to