Commit 9915dd03 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fixed strtod_l/wcstod_l implementation.

parent c4bf9fb7
...@@ -169,6 +169,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca ...@@ -169,6 +169,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
int exp=0, sign=1; int exp=0, sign=1;
const char *p; const char *p;
double ret; double ret;
BOOL found_digit = FALSE;
if(!str) { if(!str) {
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0); MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
...@@ -191,6 +192,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca ...@@ -191,6 +192,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
p++; p++;
while(isdigit(*p)) { while(isdigit(*p)) {
found_digit = TRUE;
hlp = d*10+*(p++)-'0'; hlp = d*10+*(p++)-'0';
if(d>MSVCRT_UI64_MAX/10 || hlp<d) { if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
exp++; exp++;
...@@ -207,6 +209,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca ...@@ -207,6 +209,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
p++; p++;
while(isdigit(*p)) { while(isdigit(*p)) {
found_digit = TRUE;
hlp = d*10+*(p++)-'0'; hlp = d*10+*(p++)-'0';
if(d>MSVCRT_UI64_MAX/10 || hlp<d) if(d>MSVCRT_UI64_MAX/10 || hlp<d)
break; break;
...@@ -217,7 +220,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca ...@@ -217,7 +220,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
while(isdigit(*p)) while(isdigit(*p))
p++; p++;
if(p == str) { if(!found_digit) {
if(end) if(end)
*end = (char*)str; *end = (char*)str;
return 0.0; return 0.0;
......
...@@ -1096,6 +1096,7 @@ static void test__strtod(void) ...@@ -1096,6 +1096,7 @@ static void test__strtod(void)
const char double4[] = ".21e12"; const char double4[] = ".21e12";
const char double5[] = "214353e-3"; const char double5[] = "214353e-3";
const char overflow[] = "1d9999999999999999999"; const char overflow[] = "1d9999999999999999999";
const char white_chars[] = " d10";
char *end; char *end;
double d; double d;
...@@ -1123,6 +1124,10 @@ static void test__strtod(void) ...@@ -1123,6 +1124,10 @@ static void test__strtod(void)
d = strtod("12.1d2", NULL); d = strtod("12.1d2", NULL);
ok(almost_equal(d, 12.1e2), "d = %lf\n", d); ok(almost_equal(d, 12.1e2), "d = %lf\n", d);
d = strtod(white_chars, &end);
ok(almost_equal(d, 0), "d = %lf\n", d);
ok(end == white_chars, "incorrect end (%d)\n", (int)(end-white_chars));
/* Set locale with non '.' decimal point (',') */ /* Set locale with non '.' decimal point (',') */
if(!setlocale(LC_ALL, "Polish")) { if(!setlocale(LC_ALL, "Polish")) {
win_skip("system with limited locales\n"); win_skip("system with limited locales\n");
......
...@@ -133,6 +133,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end, ...@@ -133,6 +133,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
int exp=0, sign=1; int exp=0, sign=1;
const MSVCRT_wchar_t *p; const MSVCRT_wchar_t *p;
double ret; double ret;
BOOL found_digit = FALSE;
if(!str) { if(!str) {
MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0); MSVCRT__invalid_parameter(NULL, NULL, NULL, 0, 0);
...@@ -154,6 +155,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end, ...@@ -154,6 +155,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
p++; p++;
while(isdigitW(*p)) { while(isdigitW(*p)) {
found_digit = TRUE;
hlp = d*10+*(p++)-'0'; hlp = d*10+*(p++)-'0';
if(d>MSVCRT_UI64_MAX/10 || hlp<d) { if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
exp++; exp++;
...@@ -169,6 +171,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end, ...@@ -169,6 +171,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
p++; p++;
while(isdigitW(*p)) { while(isdigitW(*p)) {
found_digit = TRUE;
hlp = d*10+*(p++)-'0'; hlp = d*10+*(p++)-'0';
if(d>MSVCRT_UI64_MAX/10 || hlp<d) if(d>MSVCRT_UI64_MAX/10 || hlp<d)
break; break;
...@@ -179,7 +182,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end, ...@@ -179,7 +182,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
while(isdigitW(*p)) while(isdigitW(*p))
p++; p++;
if(p == str) { if(!found_digit) {
if(end) if(end)
*end = (MSVCRT_wchar_t*)str; *end = (MSVCRT_wchar_t*)str;
return 0.0; return 0.0;
......
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