msvcrt: Fix space-only inputs in wcstoi64.

wcstoi64 sets endpos past the beginning only if some digits are found.

Signed-off-by: Lauri Kenttä <lauri.kentta@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Lauri Kenttä 2017-01-25 17:02:26 +02:00 committed by Alexandre Julliard
parent 5b6e1cf2de
commit 96a48efeea
2 changed files with 17 additions and 4 deletions

View File

@ -2827,6 +2827,7 @@ static void test__stricmp(void)
static void test__wcstoi64(void)
{
static const WCHAR digit[] = { '9', 0 };
static const WCHAR space[] = { ' ', 0 };
static const WCHAR stock[] = { 0x3231, 0 }; /* PARENTHESIZED IDEOGRAPH STOCK */
static const WCHAR cjk_1[] = { 0x4e00, 0 }; /* CJK Ideograph, First */
static const WCHAR tamil[] = { 0x0bef, 0 }; /* TAMIL DIGIT NINE */
@ -2853,6 +2854,8 @@ static void test__wcstoi64(void)
res = p_wcstoi64(digit, NULL, 10);
ok(res == 9, "res != 9\n");
res = p_wcstoi64(space, &endpos, 0);
ok(endpos == space, "endpos != space\n");
res = p_wcstoi64(stock, &endpos, 10);
ok(res == 0, "res != 0\n");
ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);
@ -2876,6 +2879,8 @@ static void test__wcstoi64(void)
ures = p_wcstoui64(digit, NULL, 10);
ok(ures == 9, "ures != 9\n");
ures = p_wcstoui64(space, &endpos, 0);
ok(endpos == space, "endpos != space\n");
ures = p_wcstoui64(stock, &endpos, 10);
ok(ures == 0, "ures != 0\n");
ok(endpos == stock, "Incorrect endpos (%p-%p)\n", stock, endpos);

View File

@ -2053,7 +2053,7 @@ static int wctoint(WCHAR c, int base)
__int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
{
BOOL negative = FALSE;
BOOL negative = FALSE, empty = TRUE;
__int64 ret = 0;
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
@ -2062,6 +2062,9 @@ __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
if(endptr)
*endptr = (MSVCRT_wchar_t*)nptr;
while(isspaceW(*nptr)) nptr++;
if(*nptr == '-') {
@ -2091,6 +2094,7 @@ __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
v = -v;
nptr++;
empty = FALSE;
if(!negative && (ret>MSVCRT_I64_MAX/base || ret*base>MSVCRT_I64_MAX-v)) {
ret = MSVCRT_I64_MAX;
@ -2102,7 +2106,7 @@ __int64 CDECL MSVCRT__wcstoi64_l(const MSVCRT_wchar_t *nptr,
ret = ret*base + v;
}
if(endptr)
if(endptr && !empty)
*endptr = (MSVCRT_wchar_t*)nptr;
return ret;
@ -2209,7 +2213,7 @@ MSVCRT_longlong __cdecl MSVCRT__wtoll(const MSVCRT_wchar_t *str)
unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
MSVCRT_wchar_t **endptr, int base, MSVCRT__locale_t locale)
{
BOOL negative = FALSE;
BOOL negative = FALSE, empty = TRUE;
unsigned __int64 ret = 0;
TRACE("(%s %p %d %p)\n", debugstr_w(nptr), endptr, base, locale);
@ -2218,6 +2222,9 @@ unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
if (!MSVCRT_CHECK_PMT(base == 0 || base >= 2)) return 0;
if (!MSVCRT_CHECK_PMT(base <= 36)) return 0;
if(endptr)
*endptr = (MSVCRT_wchar_t*)nptr;
while(isspaceW(*nptr)) nptr++;
if(*nptr == '-') {
@ -2244,6 +2251,7 @@ unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
break;
nptr++;
empty = FALSE;
if(ret>MSVCRT_UI64_MAX/base || ret*base>MSVCRT_UI64_MAX-v) {
ret = MSVCRT_UI64_MAX;
@ -2252,7 +2260,7 @@ unsigned __int64 CDECL MSVCRT__wcstoui64_l(const MSVCRT_wchar_t *nptr,
ret = ret*base + v;
}
if(endptr)
if(endptr && !empty)
*endptr = (MSVCRT_wchar_t*)nptr;
return negative ? -ret : ret;