summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorMichael Widenius <monty@askmonty.org>2011-11-23 19:32:14 +0200
committerMichael Widenius <monty@askmonty.org>2011-11-23 19:32:14 +0200
commit7b368e3810feda53fc0dbdf5bfe8863f82f0bbcc (patch)
treebab573449ec11585c1b5149c7cbf477178caa469 /strings
parentc8768a091ac2d876216582813aaab7d9663008f7 (diff)
parentf28e7bd0645d478d33d7ae3b974931c7991cd0bd (diff)
downloadmariadb-git-7b368e3810feda53fc0dbdf5bfe8863f82f0bbcc.tar.gz
Merge with MySQL 5.1.60
Diffstat (limited to 'strings')
-rw-r--r--strings/decimal.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index f4a2621e194..8e30308d359 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1494,9 +1494,8 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
{
int frac0=scale>0 ? ROUND_UP(scale) : scale/DIG_PER_DEC1,
frac1=ROUND_UP(from->frac), UNINIT_VAR(round_digit),
- intg0=ROUND_UP(from->intg), error=E_DEC_OK, len=to->len,
- intg1=ROUND_UP(from->intg +
- (((intg0 + frac0)>0) && (from->buf[0] == DIG_MAX)));
+ intg0=ROUND_UP(from->intg), error=E_DEC_OK, len=to->len;
+
dec1 *buf0=from->buf, *buf1=to->buf, x, y, carry=0;
int first_dig;
@@ -1511,6 +1510,12 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
default: DBUG_ASSERT(0);
}
+ /*
+ For my_decimal we always use len == DECIMAL_BUFF_LENGTH == 9
+ For internal testing here (ifdef MAIN) we always use len == 100/4
+ */
+ DBUG_ASSERT(from->len == to->len);
+
if (unlikely(frac0+intg0 > len))
{
frac0=len-intg0;
@@ -1524,17 +1529,17 @@ decimal_round(decimal_t *from, decimal_t *to, int scale,
return E_DEC_OK;
}
- if (to != from || intg1>intg0)
+ if (to != from)
{
dec1 *p0= buf0+intg0+max(frac1, frac0);
- dec1 *p1= buf1+intg1+max(frac1, frac0);
+ dec1 *p1= buf1+intg0+max(frac1, frac0);
+
+ DBUG_ASSERT(p0 - buf0 <= len);
+ DBUG_ASSERT(p1 - buf1 <= len);
while (buf0 < p0)
*(--p1) = *(--p0);
- if (unlikely(intg1 > intg0))
- to->buf[0]= 0;
- intg0= intg1;
buf0=to->buf;
buf1=to->buf;
to->sign=from->sign;