Commit df1f7cab authored by unknown's avatar unknown

fix decimal2longlong too


mysql-test/r/rpl_start_stop_slave.result:
  results updated
parent 87347253
slave stop; stop slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
reset master; reset master;
reset slave; reset slave;
drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9;
slave start; start slave;
stop slave; stop slave;
create table t1(n int); create table t1(n int);
start slave; start slave;
......
...@@ -532,7 +532,7 @@ int decimal2longlong(decimal *from, longlong *to) ...@@ -532,7 +532,7 @@ int decimal2longlong(decimal *from, longlong *to)
{ {
dec1 *buf=from->buf; dec1 *buf=from->buf;
longlong x=0; longlong x=0;
int intg; int intg, frac;
for (intg=from->intg; intg > 0; intg-=DIG_PER_DEC1) for (intg=from->intg; intg > 0; intg-=DIG_PER_DEC1)
{ {
...@@ -540,11 +540,11 @@ int decimal2longlong(decimal *from, longlong *to) ...@@ -540,11 +540,11 @@ int decimal2longlong(decimal *from, longlong *to)
/* /*
Attention: trick! Attention: trick!
we're calculating -|from| instead of |from| here we're calculating -|from| instead of |from| here
because |MIN_LONGLONG| > MAX_LONGLONG because |LONGLONG_MIN| > LONGLONG_MAX
so we can convert -9223372036854775808 correctly so we can convert -9223372036854775808 correctly
*/ */
x=x*DIG_BASE - *buf++; x=x*DIG_BASE - *buf++;
if (unlikely(x > y)) if (unlikely(y < (LONGLONG_MAX/DIG_BASE) || x > y))
{ {
*to= from->sign ? y : -y; *to= from->sign ? y : -y;
return E_DEC_OVERFLOW; return E_DEC_OVERFLOW;
...@@ -558,7 +558,10 @@ int decimal2longlong(decimal *from, longlong *to) ...@@ -558,7 +558,10 @@ int decimal2longlong(decimal *from, longlong *to)
} }
*to=from->sign ? x : -x; *to=from->sign ? x : -x;
return from->frac ? E_DEC_TRUNCATED : E_DEC_OK; for (frac=from->frac; unlikely(frac > 0); frac-=DIG_PER_DEC1)
if (*buf++)
return E_DEC_TRUNCATED;
return E_DEC_OK;
} }
/* /*
......
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