Quantcast

OpenBSD csh: incorrect precedence for arithmetic operators

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

OpenBSD csh: incorrect precedence for arithmetic operators

Gilles Filippini
Hi,

This bug was reported [1] on debian against the OpenBSD implementation
of csh.

[1] https://bugs.debian.org/862221

The current code in exp.c:exp4() and exp.c:exp5() makes sequances of
ADDOP (resp. MULOP) evaluated from the right to the left. This is wrong,
especially when '-' (resp. '/') is the first operator of the sequence:
 $ /bin/bsd-csh -c "@ var = 10 - 2 + 4; echo \$var # should be 12"
 4 # should be 12
 $ /bin/bsd-csh -c "@ var = 100 / 10 / 5; echo \$var # should be 2"
 50 # should be 2

The TENEX implementation (tcsh) gives the correct results:
 $ /bin/tcsh -c "@ var = 10 - 2 + 4; echo \$var # should be 12"
 12 # should be 12
 $ /bin/tcsh -c "@ var = 100 / 10 / 5; echo \$var # should be 2"
 2 # should be 2

Please find attached a very simple fix.

Thanks,

_g.

csh-arithmetic-fix.patch (1K) Download Attachment
signature.asc (519 bytes) Download Attachment
Loading...