summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2018-02-25 23:59:01 +0400
committerAlexander Barkov <bar@mariadb.org>2018-02-25 23:59:01 +0400
commitd0cc7a52255fd39dda8b73828e26d3541e0b0c64 (patch)
tree690678affe368bb7068767d4863f9bc165f2ba8c /strings
parente826d1e64d4c03f2365763f64c180b67ed95bb53 (diff)
downloadmariadb-git-d0cc7a52255fd39dda8b73828e26d3541e0b0c64.tar.gz
MDEV-15420 Wrong result for CAST from TIME or DATETIME with zero integer part and non-zero microseconds to DECIMAL(X,Y)
The loop in ull2dec() does not iterate if "from" is zero, so to->intg got erroneously set to 0 instead of 1. Because if this, my_decimal2seconds() wrote the fractional part into a wrong buf[x]. Catching the special case with zero "from" and properly initialize "to" using decimal_make_zero().
Diffstat (limited to 'strings')
-rw-r--r--strings/decimal.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 7db5111fc84..029a85b3202 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1000,6 +1000,12 @@ static int ull2dec(ulonglong from, decimal_t *to)
sanity(to);
+ if (!from)
+ {
+ decimal_make_zero(to);
+ return E_DEC_OK;
+ }
+
for (intg1=1; from >= DIG_BASE; intg1++, from/=DIG_BASE) {}
if (unlikely(intg1 > to->len))
{