sh: Allow arbitrarily large numbers in break and continue.

The argument is capped to loopnest, so strtol()'s [ERANGE] can be ignored.
This commit is contained in:
Jilles Tjoelker 2014-07-20 20:29:09 +00:00
parent 120d6dd50d
commit 4d34663be3
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=268927
3 changed files with 18 additions and 1 deletions

View File

@ -1250,8 +1250,16 @@ bltincmd(int argc, char **argv)
int
breakcmd(int argc, char **argv)
{
int n = argc > 1 ? number(argv[1]) : 1;
long n;
char *end;
if (argc > 1) {
/* Allow arbitrarily large numbers. */
n = strtol(argv[1], &end, 10);
if (!is_digit(argv[1][0]) || *end != '\0')
error("Illegal number: %s", argv[1]);
} else
n = 1;
if (n > loopnest)
n = loopnest;
if (n > 0) {

View File

@ -14,6 +14,7 @@ FILES+= break2.0 break2.0.stdout
FILES+= break3.0
FILES+= break4.4
FILES+= break5.4
FILES+= break6.0
FILES+= builtin1.0
FILES+= case1.0
FILES+= case2.0

View File

@ -0,0 +1,8 @@
# $FreeBSD$
# Per POSIX, this need only work if LONG_MAX > 4294967295.
while :; do
break 4294967296
echo bad
exit 3
done