Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 24 Aug 2013 20:06:00 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r254806 - in head: bin/sh tools/regression/bin/sh/expansion
Message-ID:  <201308242006.r7OK60e0036247@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201308242006.r7OK60e0036247>