Commit 0922865b authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix strtol implementation on strings not containing valid number.

parent 7a02782f
......@@ -839,7 +839,9 @@ MSVCRT_size_t CDECL MSVCRT_strnlen(const char *s, MSVCRT_size_t maxlen)
*/
__int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
{
const char *p = nptr;
BOOL negative = FALSE;
BOOL got_digit = FALSE;
__int64 ret = 0;
TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
......@@ -881,6 +883,7 @@ __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCR
break;
v = cur-'a'+10;
}
got_digit = TRUE;
if(negative)
v = -v;
......@@ -898,7 +901,7 @@ __int64 CDECL MSVCRT_strtoi64_l(const char *nptr, char **endptr, int base, MSVCR
}
if(endptr)
*endptr = (char*)nptr;
*endptr = (char*)(got_digit ? nptr : p);
return ret;
}
......@@ -1014,7 +1017,9 @@ MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
*/
unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int base, MSVCRT__locale_t locale)
{
const char *p = nptr;
BOOL negative = FALSE;
BOOL got_digit = FALSE;
unsigned __int64 ret = 0;
TRACE("(%s %p %d %p)\n", debugstr_a(nptr), endptr, base, locale);
......@@ -1056,6 +1061,7 @@ unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int b
break;
v = cur-'a'+10;
}
got_digit = TRUE;
nptr++;
......@@ -1067,7 +1073,7 @@ unsigned __int64 CDECL MSVCRT_strtoui64_l(const char *nptr, char **endptr, int b
}
if(endptr)
*endptr = (char*)nptr;
*endptr = (char*)(got_digit ? nptr : p);
return negative ? -ret : ret;
}
......
......@@ -1401,6 +1401,8 @@ static void test_strtok(void)
static void test_strtol(void)
{
static char neg[] = "-0x";
char* e;
LONG l;
ULONG ul;
......@@ -1457,6 +1459,12 @@ static void test_strtol(void)
ul = strtoul("-4294967296", NULL, 0);
ok(ul == 1, "wrong value %u\n", ul);
ok(errno == ERANGE, "wrong errno %d\n", errno);
errno = 0;
l = strtol(neg, &e, 0);
ok(l == 0, "wrong value %d\n", l);
ok(errno == 0, "wrong errno %d\n", errno);
ok(e == neg, "e = %p, neg = %p\n", e, neg);
}
static void test_strnlen(void)
......
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