Commit 8ded4110 authored by Chaithra Reddy's avatar Chaithra Reddy

Bug#18469276: MOD FOR SMALL DECIMALS FAILS

      
Problem:
If leading zeroes of fractional part of a decimal
number exceeds 45, mod operation on the same fails.
      
Analysis:
Currently there is a miscalcultion of fractional
part for very small decimals in do_div_mod.
      
For ex:
For 0.000(45 times).....3
length of the integer part becomes -5 (for a length of one,
buffer can hold 9 digits. Since number of zeroes are 45, integer
part becomes 5) and it is negative because of the leading
zeroes present in the fractional part.
Fractional part is the number of digits present after the
point which is 46 and therefore rounded off to the nearest 9
multiple which is 54. So the length of the resulting fractional
part becomes 6.
      
Because of this, the combined length of integer part and fractional
part exceeds the max length allocated which is 9 and thereby failing.
      
Solution:
In case of negative integer value, it indicates there are
leading zeroes in fractional part. As a result stop1 pointer 
should be set not just based on frac0 but also intg0. This is
because the detination buffer will be filled with 0's for the length
of intg0.

strings/decimal.c:
  Calculate stop1 pointer based on the length of intg0 and frac0.
parent 301032d2
/* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -2322,7 +2322,7 @@ static int do_div_mod(const decimal_t *from1, const decimal_t *from2,
error=E_DEC_TRUNCATED;
goto done;
}
stop1=start1+frac0;
stop1= start1 + frac0 + intg0;
frac0+=intg0;
to->intg=0;
while (intg0++ < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment