After entering an invalid three-letter card name, one letter card names
authorschwarze <schwarze@openbsd.org>
Fri, 9 May 2014 02:47:25 +0000 (02:47 +0000)
committerschwarze <schwarze@openbsd.org>
Fri, 9 May 2014 02:47:25 +0000 (02:47 +0000)
stopped working because the third letter remained in the buffer,
incard() skipped the NUL and used the old garbage.
Fix this bug reported by pjanzen@, but in a simpler way than he
suggested, by just clearing any trailing garbage from the buffer.
ok pjanzen@

games/cribbage/io.c

index 551c5c9..3696d18 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: io.c,v 1.15 2014/05/09 00:03:41 schwarze Exp $        */
+/*     $OpenBSD: io.c,v 1.16 2014/05/09 02:47:25 schwarze Exp $        */
 /*     $NetBSD: io.c,v 1.9 1997/07/09 06:25:47 phil Exp $      */
 
 /*-
@@ -552,7 +552,8 @@ get_line(void)
                        Mpos++;
                }
        }
-       linebuf[pos] = '\0';
+       while (pos < sizeof(linebuf))
+               linebuf[pos++] = '\0';
        stdscr = oscr;
        return (linebuf);
 }