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:
parent
7c14da7202
commit
7e6e930d1e
@ -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 '~':
|
||||
|
6
tools/regression/bin/sh/expansion/arith13.0
Normal file
6
tools/regression/bin/sh/expansion/arith13.0
Normal 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
|
Loading…
x
Reference in New Issue
Block a user