From 88ff9c0697c57951fd41e8543aacb033ef78a94f Mon Sep 17 00:00:00 2001 From: dholland Date: Sat, 13 Oct 2012 20:36:06 +0000 Subject: Pass -Wstrict-overflow, and while here, don't read from index -1 of an array. --- cribbage/crib.c | 6 +++--- cribbage/cribbage.h | 6 +++--- cribbage/io.c | 32 ++++++++++++++++---------------- cribbage/score.c | 17 +++++++++-------- 4 files changed, 31 insertions(+), 30 deletions(-) diff --git a/cribbage/crib.c b/cribbage/crib.c index aef76a8a..130c3212 100644 --- a/cribbage/crib.c +++ b/cribbage/crib.c @@ -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, 1993\ #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) diff --git a/cribbage/cribbage.h b/cribbage/cribbage.h index d27d2bab..6abe6916 100644 --- a/cribbage/cribbage.h +++ b/cribbage/cribbage.h @@ -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 []); diff --git a/cribbage/io.c b/cribbage/io.c index ed750784..cc1243df 100644 --- a/cribbage/io.c +++ b/cribbage/io.c @@ -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 22:48:52 joerg Exp $"); #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 char *mid, BOOLEAN brfsuit) * 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, BOOLEAN blank) * 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); } 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; -- cgit v1.2.3-56-ge451