svn commit: r254806 - in head: bin/sh tools/regression/bin/sh/expansion
Jilles Tjoelker
jilles at FreeBSD.org
Sat Aug 24 20:06:00 UTC 2013
Author: jilles
Date: Sat Aug 24 20:06:00 2013
New Revision: 254806
URL: http://svnweb.freebsd.org/changeset/base/254806
Log:
sh: Reject ++ and -- in arithmetic.
POSIX does not require ++ and -- in arithmetic. It is probably more useful
to reject them than to treat ++x and --x as x silently.
Note that the behaviour of increment and decrement can be obtained via
(x+=1), ((x+=1)-1), (x-=1) and ((x-=1)+1).
PR: bin/176444
Added:
head/tools/regression/bin/sh/expansion/arith13.0 (contents, props changed)
Modified:
head/bin/sh/arith_yylex.c
Modified: head/bin/sh/arith_yylex.c
==============================================================================
--- head/bin/sh/arith_yylex.c Sat Aug 24 19:58:36 2013 (r254805)
+++ head/bin/sh/arith_yylex.c Sat Aug 24 20:06:00 2013 (r254806)
@@ -218,9 +218,13 @@ checkeqcur:
value += ARITH_REM - '%';
goto checkeq;
case '+':
+ if (buf[1] == '+')
+ return ARITH_BAD;
value += ARITH_ADD - '+';
goto checkeq;
case '-':
+ if (buf[1] == '-')
+ return ARITH_BAD;
value += ARITH_SUB - '-';
goto checkeq;
case '~':
Added: head/tools/regression/bin/sh/expansion/arith13.0
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ head/tools/regression/bin/sh/expansion/arith13.0 Sat Aug 24 20:06:00 2013 (r254806)
@@ -0,0 +1,6 @@
+# $FreeBSD$
+# Pre-increment and pre-decrement in arithmetic expansion are not in POSIX.
+# Require either an error or a correct implementation.
+
+! (eval 'x=4; [ $((++x)) != 5 ] || [ $x != 5 ]') 2>/dev/null &&
+! (eval 'x=2; [ $((--x)) != 1 ] || [ $x != 1 ]') 2>/dev/null
More information about the svn-src-all
mailing list