Source-Changes-HG archive

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

[src/trunk]: src/bin/sh POSIX says that the arg to break or continue is to be...



details:   https://anonhg.NetBSD.org/src/rev/fe26ba5f1c28
branches:  trunk
changeset: 823754:fe26ba5f1c28
user:      kre <kre%NetBSD.org@localhost>
date:      Sun May 07 10:37:00 2017 +0000

description:
POSIX says that the arg to break or continue is to be a positive integer
(by which they mean > 0).  We were checking for negative numbers, but
not for 0.  More by chance of the implementation than any specific design
(I suspect) "break 0" was being treated the same as "break" or "break 1".
Since 3 ways to achieve the same thing is overkill, let's do what posix
wants and forbid "break 0" and "continue 0".

diffstat:

 bin/sh/eval.c |  6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r ae00dbdff9d7 -r fe26ba5f1c28 bin/sh/eval.c
--- a/bin/sh/eval.c     Sun May 07 08:26:58 2017 +0000
+++ b/bin/sh/eval.c     Sun May 07 10:37:00 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: eval.c,v 1.134 2017/05/04 04:37:51 kre Exp $   */
+/*     $NetBSD: eval.c,v 1.135 2017/05/07 10:37:00 kre Exp $   */
 
 /*-
  * Copyright (c) 1993
@@ -37,7 +37,7 @@
 #if 0
 static char sccsid[] = "@(#)eval.c     8.9 (Berkeley) 6/8/95";
 #else
-__RCSID("$NetBSD: eval.c,v 1.134 2017/05/04 04:37:51 kre Exp $");
+__RCSID("$NetBSD: eval.c,v 1.135 2017/05/07 10:37:00 kre Exp $");
 #endif
 #endif /* not lint */
 
@@ -1231,6 +1231,8 @@
 {
        int n = argc > 1 ? number(argv[1]) : 1;
 
+       if (n <= 0)
+               error("invalid count: %d", n);
        if (n > loopnest)
                n = loopnest;
        if (n > 0) {



Home | Main Index | Thread Index | Old Index