Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/cribbage Pass -Wstrict-overflow, and while here, don't...



details:   https://anonhg.NetBSD.org/src/rev/67d9881054e9
branches:  trunk
changeset: 782056:67d9881054e9
user:      dholland <dholland%NetBSD.org@localhost>
date:      Sat Oct 13 20:36:06 2012 +0000

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

diffstat:

 games/cribbage/crib.c     |   6 +++---
 games/cribbage/cribbage.h |   6 +++---
 games/cribbage/io.c       |  32 ++++++++++++++++----------------
 games/cribbage/score.c    |  17 +++++++++--------
 4 files changed, 31 insertions(+), 30 deletions(-)

diffs (201 lines):

diff -r b1551f965a3a -r 67d9881054e9 games/cribbage/crib.c
--- a/games/cribbage/crib.c     Sat Oct 13 20:12:18 2012 +0000
+++ b/games/cribbage/crib.c     Sat Oct 13 20:36:06 2012 +0000
@@ -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 @@
 #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 @@
  *     Handle all the pegging...
  */
 static CARD Table[14];
-static int Tcnt;
+static unsigned Tcnt;
 
 static int
 peg(BOOLEAN mycrib)
diff -r b1551f965a3a -r 67d9881054e9 games/cribbage/cribbage.h
--- a/games/cribbage/cribbage.h Sat Oct 13 20:12:18 2012 +0000
+++ b/games/cribbage/cribbage.h Sat Oct 13 20:36:06 2012 +0000
@@ -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    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 -r b1551f965a3a -r 67d9881054e9 games/cribbage/io.c
--- a/games/cribbage/io.c       Sat Oct 13 20:12:18 2012 +0000
+++ b/games/cribbage/io.c       Sat Oct 13 20:36:06 2012 +0000
@@ -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 @@
 #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 @@
  *     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 @@
  *     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 @@
 char *
 get_line(void)
 {
-       char *sp;
+       size_t pos;
        int c, oy, ox;
        WINDOW *oscr;
 
@@ -528,36 +528,36 @@
        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 -r b1551f965a3a -r 67d9881054e9 games/cribbage/score.c
--- a/games/cribbage/score.c    Sat Oct 13 20:12:18 2012 +0000
+++ b/games/cribbage/score.c    Sat Oct 13 20:36:06 2012 +0000
@@ -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 @@
  * 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 @@
                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;



Home | Main Index | Thread Index | Old Index