summaryrefslogtreecommitdiff
path: root/strings/decimal.c
diff options
context:
space:
mode:
authorunknown <ramil@ram-book.(none)>2005-05-06 13:31:48 +0500
committerunknown <ramil@ram-book.(none)>2005-05-06 13:31:48 +0500
commit56426fca8888bd867f6862561ae17fe6f5ca6669 (patch)
treed686b7e8bb90dcf3b44405371fee922c20f98453 /strings/decimal.c
parente5670bf24816427be59c39dfd9419214f68172af (diff)
downloadmariadb-git-56426fca8888bd867f6862561ae17fe6f5ca6669.tar.gz
A fix (bug #10404: select 0/0 returns 0).
strings/decimal.c: A fix (bug #10404: select 0/0 returns 0). We should check the second argument (0?) first.
Diffstat (limited to 'strings/decimal.c')
-rw-r--r--strings/decimal.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/strings/decimal.c b/strings/decimal.c
index 52003a930c0..4b7dc8803ee 100644
--- a/strings/decimal.c
+++ b/strings/decimal.c
@@ -1945,6 +1945,18 @@ static int do_div_mod(decimal_t *from1, decimal_t *from2,
sanity(to);
/* removing all the leading zeroes */
+ i= ((prec2 - 1) % DIG_PER_DEC1) + 1;
+ while (prec2 > 0 && *buf2 == 0)
+ {
+ prec2-= i;
+ i= DIG_PER_DEC1;
+ buf2++;
+ }
+ if (prec2 <= 0) /* short-circuit everything: from2 == 0 */
+ return E_DEC_DIV_ZERO;
+ for (i= (prec2 - 1) % DIG_PER_DEC1; *buf2 < powers10[i--]; prec2--) ;
+ DBUG_ASSERT(prec2 > 0);
+
i=((prec1-1) % DIG_PER_DEC1)+1;
while (prec1 > 0 && *buf1 == 0)
{
@@ -1960,19 +1972,6 @@ static int do_div_mod(decimal_t *from1, decimal_t *from2,
for (i=(prec1-1) % DIG_PER_DEC1; *buf1 < powers10[i--]; prec1--) ;
DBUG_ASSERT(prec1 > 0);
- i=((prec2-1) % DIG_PER_DEC1)+1;
- while (prec2 > 0 && *buf2 == 0)
- {
- prec2-=i;
- i=DIG_PER_DEC1;
- buf2++;
- }
- if (prec2 <= 0) /* short-circuit everything: from2 == 0 */
- return E_DEC_DIV_ZERO;
-
- for (i=(prec2-1) % DIG_PER_DEC1; *buf2 < powers10[i--]; prec2--) ;
- DBUG_ASSERT(prec2 > 0);
-
/* let's fix scale_incr, taking into account frac1,frac2 increase */
if ((scale_incr-= frac1 - from1->frac + frac2 - from2->frac) < 0)
scale_incr=0;
@@ -2723,6 +2722,7 @@ int main()
test_dv("123", "0.01","12300.000000000", 0);
test_dv("120", "100000000000.00000","0.000000001200000000", 0);
test_dv("123", "0","", 4);
+ test_dv("0", "0", "", 4);
test_dv("-12193185.1853376", "98765.4321","-123.456000000000000000", 0);
test_dv("121931851853376", "987654321","123456.000000000", 0);
test_dv("0", "987","0", 0);