Piotr Caban : msvcrt: Fixed strtod_l/wcstod_l implementation.

Alexandre Julliard julliard at winehq.org
Thu Jul 22 12:09:35 CDT 2010


Module: wine
Branch: master
Commit: 9915dd03b432664c15ce4d1a1b8a019aee53c739
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=9915dd03b432664c15ce4d1a1b8a019aee53c739

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Thu Jul 22 12:35:08 2010 +0200

msvcrt: Fixed strtod_l/wcstod_l implementation.

---

 dlls/msvcrt/string.c       |    5 ++++-
 dlls/msvcrt/tests/string.c |    5 +++++
 dlls/msvcrt/wcs.c          |    5 ++++-
 3 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c
index 8c99399..f44e6eb 100644
--- a/dlls/msvcrt/string.c
+++ b/dlls/msvcrt/string.c
@@ -169,6 +169,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
     int exp=0, sign=1;
     const char *p;
     double ret;
+    BOOL found_digit = FALSE;
 
     if(!str) {
         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
         p++;
 
     while(isdigit(*p)) {
+        found_digit = TRUE;
         hlp = d*10+*(p++)-'0';
         if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
             exp++;
@@ -207,6 +209,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
         p++;
 
     while(isdigit(*p)) {
+        found_digit = TRUE;
         hlp = d*10+*(p++)-'0';
         if(d>MSVCRT_UI64_MAX/10 || hlp<d)
             break;
@@ -217,7 +220,7 @@ double CDECL MSVCRT_strtod_l( const char *str, char **end, MSVCRT__locale_t loca
     while(isdigit(*p))
         p++;
 
-    if(p == str) {
+    if(!found_digit) {
         if(end)
             *end = (char*)str;
         return 0.0;
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index 55cb5e4..e2324b0 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -1096,6 +1096,7 @@ static void test__strtod(void)
     const char double4[] = ".21e12";
     const char double5[] = "214353e-3";
     const char overflow[] = "1d9999999999999999999";
+    const char white_chars[] = "  d10";
 
     char *end;
     double d;
@@ -1123,6 +1124,10 @@ static void test__strtod(void)
     d = strtod("12.1d2", NULL);
     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 (',') */
     if(!setlocale(LC_ALL, "Polish")) {
         win_skip("system with limited locales\n");
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c
index 03ecc7f..529547b 100644
--- a/dlls/msvcrt/wcs.c
+++ b/dlls/msvcrt/wcs.c
@@ -133,6 +133,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
     int exp=0, sign=1;
     const MSVCRT_wchar_t *p;
     double ret;
+    BOOL found_digit = FALSE;
 
     if(!str) {
         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,
         p++;
 
     while(isdigitW(*p)) {
+        found_digit = TRUE;
         hlp = d*10+*(p++)-'0';
         if(d>MSVCRT_UI64_MAX/10 || hlp<d) {
             exp++;
@@ -169,6 +171,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
         p++;
 
     while(isdigitW(*p)) {
+        found_digit = TRUE;
         hlp = d*10+*(p++)-'0';
         if(d>MSVCRT_UI64_MAX/10 || hlp<d)
             break;
@@ -179,7 +182,7 @@ double CDECL MSVCRT__wcstod_l(const MSVCRT_wchar_t* str, MSVCRT_wchar_t** end,
     while(isdigitW(*p))
         p++;
 
-    if(p == str) {
+    if(!found_digit) {
         if(end)
             *end = (MSVCRT_wchar_t*)str;
         return 0.0;




More information about the wine-cvs mailing list