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
This commit is contained in:
Jilles Tjoelker 2013-08-24 20:06:00 +00:00
parent 7c14da7202
commit 7e6e930d1e
2 changed files with 10 additions and 0 deletions

View File

@ -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 '~':

View File

@ -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