diff options
author | unknown <serg@serg.mylan> | 2004-11-27 12:35:21 +0100 |
---|---|---|
committer | unknown <serg@serg.mylan> | 2004-11-27 12:35:21 +0100 |
commit | 368cde22ac949bf4380cb012af59149a6dded2d1 (patch) | |
tree | ae05b62713c165322ee0eec717f8180474429503 /strings/decimal.c | |
parent | 2c4f2f24f212326433a756feb049247d62ee9799 (diff) | |
download | mariadb-git-368cde22ac949bf4380cb012af59149a6dded2d1.tar.gz |
better overflow checks in decimal2ulonglong
better truncation check in decimal2ulonglong
Diffstat (limited to 'strings/decimal.c')
-rw-r--r-- | strings/decimal.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/strings/decimal.c b/strings/decimal.c index b8e8fd3725f..9b418dbe550 100644 --- a/strings/decimal.c +++ b/strings/decimal.c @@ -503,7 +503,7 @@ int decimal2ulonglong(decimal *from, ulonglong *to) { dec1 *buf=from->buf; ulonglong x=0; - int intg; + int intg, frac; if (from->sign) { @@ -515,14 +515,17 @@ int decimal2ulonglong(decimal *from, ulonglong *to) { ulonglong y=x; x=x*DIG_BASE + *buf++; - if (unlikely(x < y)) + if (unlikely(y > (ULONGLONG_MAX/DIG_BASE) || x < y)) { *to=y; return E_DEC_OVERFLOW; } } *to=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; } int decimal2longlong(decimal *from, longlong *to) @@ -1928,6 +1931,7 @@ main() test_d2ull("18446744073709551616"); test_d2ull("-1"); test_d2ull("1.23"); + test_d2ull("9999999999999999999999999.000"); printf("==== longlong2decimal ====\n"); test_ll2d(LL(-12345)); |