cc: [email protected]
Subject: Re: [ast-developers] ((a[x++]++)) increments "x" twice
--------

> That problem has just been reported to the bash and zsh mailing
> lists and it seems ksh93 is also affected.
> 
> In ((a[subscript]++)), ((a[subscript]+=x)), ((a[subscript]*=x))...
> it seems subscript is expanded twice which can have nasty side
> effects such as
> 
> $ ksh -c 'x=0; ((a[++x]++)); echo $x'
> 2
> ~$ ksh -c 'for ((i=0;i<1000;i++)); do ((a[RANDOM%2]++)); done; echo 
> $((a[0]+a[1]
> ))'
> 953
> ~$ ksh -c 'for ((i=0;i<1000;i++)); do ((a[RANDOM%2]++)); done; echo 
> $((a[0]+a[1]
> ))'
> 985
> ~$ ksh -c 'for ((i=0;i<1000;i++)); do ((a[RANDOM%2]++)); done; echo 
> $((a[0]+a[1]
> ))'
> 1059
> 
> -- 
> Stephane
> _______________________________________________

Thanks, I have fixed both of these for the next update.

David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers

Reply via email to