Piotr Caban : msvcrt: Call MSVCRT_strtoi64_l in strtoul implementation.

Alexandre Julliard julliard at winehq.org
Wed Sep 25 14:18:01 CDT 2013


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

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Sep 25 14:41:52 2013 +0200

msvcrt: Call MSVCRT_strtoi64_l in strtoul implementation.

---

 dlls/msvcrt/string.c       |   47 ++++++++++++++++---------------------------
 dlls/msvcrt/tests/string.c |   20 ++++++++++++++++++
 2 files changed, 38 insertions(+), 29 deletions(-)

diff --git a/dlls/msvcrt/string.c b/dlls/msvcrt/string.c
index cdce4a2..861389b 100644
--- a/dlls/msvcrt/string.c
+++ b/dlls/msvcrt/string.c
@@ -726,35 +726,6 @@ int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str,
     return 0;
 }
 
-/******************************************************************
- *		strtoul (MSVCRT.@)
- */
-MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
-{
-    /* wrapper to forward libc error code to msvcrt's error codes */
-    unsigned long ret;
-
-    errno = 0;
-    ret = strtoul(nptr, end, base);
-    switch (errno)
-    {
-    case ERANGE:        *MSVCRT__errno() = MSVCRT_ERANGE;       break;
-    case EINVAL:        *MSVCRT__errno() = MSVCRT_EINVAL;       break;
-    default:
-        /* cope with the fact that we may use 64bit long integers on libc
-         * while msvcrt always uses 32bit long integers
-         */
-        if (ret > MSVCRT_ULONG_MAX)
-        {
-            ret = MSVCRT_ULONG_MAX;
-            *MSVCRT__errno() = MSVCRT_ERANGE;
-        }
-        break;
-    }
-
-    return ret;
-}
-
 /*********************************************************************
  *              strlen (MSVCRT.@)
  */
@@ -918,6 +889,24 @@ MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
     return ret;
 }
 
+/******************************************************************
+ *		strtoul (MSVCRT.@)
+ */
+MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
+{
+    __int64 ret = MSVCRT_strtoi64_l(nptr, end, base, NULL);
+
+    if(ret > MSVCRT_ULONG_MAX) {
+        ret = MSVCRT_ULONG_MAX;
+        *MSVCRT__errno() = MSVCRT_ERANGE;
+    }else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
+        ret = 1;
+        *MSVCRT__errno() = MSVCRT_ERANGE;
+    }
+
+    return ret;
+}
+
 /*********************************************************************
  *  _strtoui64_l (MSVCRT.@)
  *
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c
index dc90b38..3877d18 100644
--- a/dlls/msvcrt/tests/string.c
+++ b/dlls/msvcrt/tests/string.c
@@ -1341,6 +1341,26 @@ static void test_strtol(void)
     ul = strtoul("9223372036854775807L", &e, 0);
     ok(ul==4294967295ul, "wrong value %u\n", ul);
     ok(errno == ERANGE, "wrong errno %d\n", errno);
+
+    errno = 0;
+    ul = strtoul("-2", NULL, 0);
+    ok(ul == -2, "wrong value %u\n", ul);
+    ok(errno == 0, "wrong errno %d\n", errno);
+
+    errno = 0;
+    ul = strtoul("-4294967294", NULL, 0);
+    ok(ul == 2, "wrong value %u\n", ul);
+    ok(errno == 0, "wrong errno %d\n", errno);
+
+    errno = 0;
+    ul = strtoul("-4294967295", NULL, 0);
+    ok(ul==1, "wrong value %u\n", ul);
+    ok(errno == 0, "wrong errno %d\n", errno);
+
+    errno = 0;
+    ul = strtoul("-4294967296", NULL, 0);
+    ok(ul == 1, "wrong value %u\n", ul);
+    ok(errno == ERANGE, "wrong errno %d\n", errno);
 }
 
 static void test_strnlen(void)




More information about the wine-cvs mailing list