Change the add/subtract overflow checks to use an unsigned to do the op
and then cast back into the signed var to check the signs.
Make multiply shortcut on either right or left being 0.
Make multiply's overflow test not fail on simple cases like 1 * -1
Make the multiple overflow test pass all the regress tests.
Make sure all precendence is spelled out correctly (comparison does not
have the same level as the arithmetic operators..)
Break the arithemtic operators into 2 classes (+- are lower than */%)
Restructure the arithmetic code into a function either class above can call.
Finally, add a whole suite of regression tests (checked in separately) which
the previous code failed on 3 of them.
it's ignored if it would cause syntax error, otherwise treated as common
string; this is so that both 'expr -- : .' and 'expr -- foo : .' works
This addresses standards/11230 by Ben Harris.
while here, make all global variables but main() static, use const more
from old expr.c. This fixes PR # 11060.
While here, convert the code to use asprintf() instead of strdup()
followed by truncating of new string and move definition of errstr
to block where it's used.
highlights:
* / is treated correctly depending upon context (addresses PR # 10995)
* use 64 bit arithmetic, so expr is able to process integer values from
-(2**63) to (2**63 - 1)
* checks for integer over- & underflows added
* error messages improved, more error checking added
add AUTHOR section to manpage
add BUGS section, and mention possible drawbacks with other expr implementations
XXX the old expr treated empty string in arithmetic expressions as if it was 0
XXX this behaviour has been retained