summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorChaithra Reddy <chaithra.gopalareddy@oracle.com>2014-07-03 14:12:02 +0530
committerChaithra Reddy <chaithra.gopalareddy@oracle.com>2014-07-03 14:12:02 +0530
commit8ded41105758327cae175660fc53051d6d374eeb (patch)
tree6b1430b67aa569504b7b7260a4059503b22ea918 /strings
parent301032d20a4488af019e56124391cbd24ed365eb (diff)
downloadmariadb-git-8ded41105758327cae175660fc53051d6d374eeb.tar.gz
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.
Diffstat (limited to 'strings')
-rw-r--r--strings/decimal.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 39dff0723b9..4f5528fcccc 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1,4 +1,4 @@
-/* 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)