summaryrefslogtreecommitdiff
path: root/strings/strtod.c
diff options
context:
space:
mode:
authorunknown <serg@serg.mylan>2004-03-14 17:25:20 +0100
committerunknown <serg@serg.mylan>2004-03-14 17:25:20 +0100
commit22657f672c8d4c005f85cd3efc714d98b635f3f0 (patch)
tree8d62b783d18499a58998dcedd618f5eb2b66ee66 /strings/strtod.c
parentad73b5ac5b5b71fc5370d19a971c260fc0bd42c1 (diff)
downloadmariadb-git-22657f672c8d4c005f85cd3efc714d98b635f3f0.tar.gz
my_strtod fixes:
sigsegv protection (exp overflow) don't return inf! use errno=EOVERFLOW to signal an overflow (as my_strntod uses errno anyway) if errno will be too slow, my_strtod can be changed to return overflow status in a parameter (like my_strntod does) include/m_string.h: EOVERFLOW mysql-test/r/insert.result: updated mysql-test/r/mysqldump.result: updated strings/strtod.c: sigsegv protection (exp overflow) don't return inf! use errno=EOVERFLOW to signal an overflow (as my_strntod uses errno anyway) if errno will be too slow, it my_strtod can be changed to return overflow status in a parameter (like my_strntod does)
Diffstat (limited to 'strings/strtod.c')
-rw-r--r--strings/strtod.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/strings/strtod.c b/strings/strtod.c
index a06b74248cb..243322cb945 100644
--- a/strings/strtod.c
+++ b/strings/strtod.c
@@ -2,7 +2,7 @@
An alternative implementation of "strtod()" that is both
simplier, and thread-safe.
- From mit-threads as bundled with MySQL 3.22
+ From mit-threads as bundled with MySQL 3.23
SQL:2003 specifies a number as
@@ -41,6 +41,7 @@ double my_strtod(const char *str, char **end)
double result= 0.0;
int negative, ndigits;
const char *old_str;
+ my_bool overflow=0;
while (my_isspace(&my_charset_latin1, *str))
str++;
@@ -85,7 +86,8 @@ double my_strtod(const char *str, char **end)
double scaler= 1.0;
while (my_isdigit (&my_charset_latin1, *str))
{
- exp= exp*10 + *str - '0';
+ if (exp < 9999) /* protection against exp overflow */
+ exp= exp*10 + *str - '0';
str++;
}
if (exp >= 1000)
@@ -93,7 +95,7 @@ double my_strtod(const char *str, char **end)
if (neg)
result= 0.0;
else
- result= DBL_MAX*10;
+ overflow=1;
goto done;
}
while (exp >= 100)
@@ -113,6 +115,12 @@ done:
if (end)
*end = (char *)str;
+ if (overflow || ((overflow=isinf(result))))
+ {
+ result=DBL_MAX;
+ errno=EOVERFLOW;
+ }
+
return negative ? -result : result;
}