1
0
mirror of https://github.com/openbsd/src.git synced 2025-01-10 06:47:55 -08:00

from pjanzen:

Use strtonum() and error out on an unacceptable length argument rather than
reverting to default values; document maximum initial length limit.

started by a diff From: Jan Stary, who requested we document default behaviour

ok millert
This commit is contained in:
jmc 2014-01-28 14:28:44 +00:00
parent 22b9cd924a
commit 3c877182e5
2 changed files with 17 additions and 8 deletions

View File

@ -1,4 +1,4 @@
.\" $OpenBSD: worm.6,v 1.12 2009/10/22 18:07:31 sobrado Exp $
.\" $OpenBSD: worm.6,v 1.13 2014/01/28 14:28:44 jmc Exp $
.\"
.\" Copyright (c) 1989, 1993
.\" The Regents of the University of California. All rights reserved.
@ -29,7 +29,7 @@
.\"
.\" @(#)worm.6 8.1 (Berkeley) 5/31/93
.\"
.Dd $Mdocdate: October 22 2009 $
.Dd $Mdocdate: January 28 2014 $
.Dt WORM 6
.Os
.Sh NAME
@ -61,4 +61,8 @@ The current score
.Pq how much the worm has grown
is kept in the upper right corner of the screen.
.Pp
The optional argument, if present, is the initial length of the worm.
The optional argument,
.Ar size ,
is the initial length of the worm's body.
The specified length will be rejected if it causes the worm to cover
more than roughly one third of the screen.

View File

@ -1,4 +1,4 @@
/* $OpenBSD: worm.c,v 1.24 2013/08/29 20:22:21 naddy Exp $ */
/* $OpenBSD: worm.c,v 1.25 2014/01/28 14:28:44 jmc Exp $ */
/*
* Copyright (c) 1980, 1993
@ -89,6 +89,7 @@ main(int argc, char **argv)
struct timeval t, tod;
struct timezone tz;
fd_set rset;
const char *errstr;
FD_ZERO(&rset);
setbuf(stdout, outbuf);
@ -105,10 +106,14 @@ main(int argc, char **argv)
endwin();
errx(1, "screen too small");
}
if (argc == 2)
start_len = atoi(argv[1]);
if ((start_len <= 0) || (start_len > ((LINES-3) * (COLS-2)) / 3))
start_len = LENGTH;
if (argc >= 2) {
start_len = strtonum(argv[1], 1, ((LINES-3) * (COLS-2)) / 3,
&errstr);
if (errstr) {
endwin();
errx(1, "length argument is %s.", errstr);
}
}
stw = newwin(1, COLS-1, 0, 0);
tv = newwin(LINES-1, COLS-1, 1, 0);
box(tv, '*', '*');