From ab16a415234856b91347438793d460cedf162375 Mon Sep 17 00:00:00 2001 From: Daniel Lehman Date: Wed, 4 Jan 2012 13:58:23 -0800 Subject: msvcrt: make WEOF returned from swscanf signed swscanf returns -1 on Windows but 65535 on Wine WEOF is an unsigned short 0xFFFF (and should be) but when returned from scanf functions it should be signed-extended --- dlls/msvcrt/scanf.h | 2 +- dlls/msvcrt/tests/scanf.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletions(-) diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index d1ac548..9f6911e 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -26,7 +26,7 @@ #ifdef WIDE_SCANF #define _CHAR_ MSVCRT_wchar_t #define _EOF_ MSVCRT_WEOF -#define _EOF_RET MSVCRT_WEOF +#define _EOF_RET (short)MSVCRT_WEOF #define _ISSPACE_(c) MSVCRT_iswspace(c) #define _ISDIGIT_(c) MSVCRT_iswdigit(c) #define _WIDE2SUPPORTED_(c) c /* No conversion needed (wide to wide) */ diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index cbfb184..03854e4 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -243,8 +243,23 @@ static void test_sscanf_s(void) ok(i==123, "i = %d\n", i); } +static void test_swscanf( void ) +{ + wchar_t buffer[100]; + int result, ret; + static const WCHAR formatd[] = {'%','d',0}; + + /* check WEOF */ + /* WEOF is an unsigned short -1 but swscanf returns int + so it should be sign-extended */ + buffer[0] = 0; + ret = swscanf(buffer, formatd, &result); + ok( ret == (short)WEOF,"sscanf returns %x instead of %x\n", ret, WEOF ); +} + START_TEST(scanf) { test_sscanf(); test_sscanf_s(); + test_swscanf(); } -- 1.6.0.4