diff options
author | Alex Cherepanov <alex.cherepanov@artifex.com> | 2010-06-23 17:14:40 +0000 |
---|---|---|
committer | Alex Cherepanov <alex.cherepanov@artifex.com> | 2010-06-23 17:14:40 +0000 |
commit | 4c6315eccf31d0360af9d0dcfeda38e647758676 (patch) | |
tree | 6005b9a961d683ec81eb7fd7324bb7da3b1fd15c /gs/psi/zarith.c | |
parent | 1696fef90b043df8f5e6cd901f7c8adc8a66c536 (diff) |
Simplify and fix the implementation of operator --mul--, which mishandled
some cases like "16#80000000 -1 mul". Bug 691412.
git-svn-id: http://svn.ghostscript.com/ghostscript/trunk@11426 a1074d23-0009-0410-80fe-cf8c14f379e6
Diffstat (limited to 'gs/psi/zarith.c')
-rw-r--r-- | gs/psi/zarith.c | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/gs/psi/zarith.c b/gs/psi/zarith.c index 820056f77..a302f3885 100644 --- a/gs/psi/zarith.c +++ b/gs/psi/zarith.c @@ -29,7 +29,6 @@ /* Define max and min values for what will fit in value.intval. */ #define MIN_INTVAL 0x80000000 #define MAX_INTVAL 0x7fffffff -#define MAX_HALF_INTVAL 0x7fff /* <num1> <num2> add <sum> */ /* We make this into a separate procedure because */ @@ -153,25 +152,13 @@ zmul(i_ctx_t *i_ctx_p) op[-1].value.realval *= (double)op->value.intval; break; case t_integer: { - int int1 = op[-1].value.intval; - int int2 = op->value.intval; - uint abs1 = (uint)(int1 >= 0 ? int1 : -int1); - uint abs2 = (uint)(int2 >= 0 ? int2 : -int2); - float fprod; - - if ((abs1 > MAX_HALF_INTVAL || abs2 > MAX_HALF_INTVAL) && - /* At least one of the operands is very large. */ - /* Check for integer overflow. */ - abs1 != 0 && - abs2 > MAX_INTVAL / abs1 && - /* Check for the boundary case */ - (fprod = (float)int1 * int2, - (int1 * int2 != MIN_INTVAL || - fprod != (float)MIN_INTVAL)) - ) - make_real(op - 1, fprod); - else - op[-1].value.intval = int1 * int2; + double ab = (double)op[-1].value.intval * op->value.intval; + if (ab > 2147483647.) /* (double)0x7fffffff */ + make_real(op - 1, ab); + else if (ab < -2147483648.) /* (double)(int)0x80000000 */ + make_real(op - 1, ab); + else + op[-1].value.intval = (int)ab; } } } |