msvcrt: Fix wide characters handling in wscanf functions.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2017-04-03 12:45:58 +02:00 committed by Alexandre Julliard
parent a392e14243
commit e7f9b562b9
2 changed files with 19 additions and 9 deletions

View File

@ -68,11 +68,11 @@
#undef _EOF_
#define _EOF_ 0
#ifdef STRING_LEN
#ifdef WIDE_CHAR
#ifdef WIDE_SCANF
#define _GETC_(file) (consumed==length ? '\0' : (consumed++, *file++))
#else /* WIDE_CHAR */
#else /* WIDE_SCANF */
#define _GETC_(file) (consumed==length ? '\0' : (consumed++, (unsigned char)*file++))
#endif /* WIDE_CHAR */
#endif /* WIDE_SCANF */
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
#define _LOCK_FILE_(file) do {} while(0)
#define _UNLOCK_FILE_(file) do {} while(0)
@ -90,11 +90,11 @@
#endif /* SECURE */
#endif /* WIDE_SCANF */
#else /* STRING_LEN */
#ifdef WIDE_CHAR
#ifdef WIDE_SCANF
#define _GETC_(file) (consumed++, *file++)
#else /* WIDE_CHAR */
#else /* WIDE_SCANF */
#define _GETC_(file) (consumed++, (unsigned char)*file++)
#endif /* WIDE_CHAR */
#endif /* WIDE_SCANF */
#define _UNGETC_(nch, file) do { file--; consumed--; } while(0)
#define _LOCK_FILE_(file) do {} while(0)
#define _UNLOCK_FILE_(file) do {} while(0)
@ -685,7 +685,7 @@ _FUNCTION_ {
* use %%." */
while ((nch!=_EOF_) && _ISSPACE_(nch))
nch = _GETC_(file);
if (nch==*format) {
if ((_CHAR_)nch == *format) {
suppress = 1; /* whoops no field to be read */
st = 1; /* but we got what we expected */
nch = _GETC_(file);
@ -699,7 +699,7 @@ _FUNCTION_ {
* a matching non-white-space character. */
else {
/* check for character match */
if (nch == (unsigned char)*format) {
if ((_CHAR_)nch == *format) {
nch = _GETC_(file);
} else break;
}

View File

@ -252,7 +252,7 @@ static void test_sscanf( void )
ok(!strcmp(buffer, "test"), "buf %s\n", buffer);
ok(!strcmp(buffer1, "value\xda"), "buf %s\n", buffer1);
ret = sscanf("\x81test", "\x81%s", buffer);
ret = sscanf("\x81\x82test", "\x81%\x82%s", buffer);
ok(ret == 1, "got %d\n", ret);
ok(!strcmp(buffer, "test"), "buf = %s\n", buffer);
}
@ -303,6 +303,8 @@ static void test_swscanf( void )
wchar_t buffer[100];
int result, ret;
static const WCHAR formatd[] = {'%','d',0};
const WCHAR format2[] = {'a',0x1234,'%',0x1234,'%','c',0};
WCHAR c;
/* check WEOF */
/* WEOF is an unsigned short -1 but swscanf returns int
@ -312,6 +314,14 @@ static void test_swscanf( void )
/* msvcrt returns 0 but should return -1 (later versions do) */
ok( ret == (short)WEOF || broken(ret == 0),
"swscanf returns %x instead of %x\n", ret, WEOF );
buffer[0] = 'a';
buffer[1] = 0x1234;
buffer[2] = 0x1234;
buffer[3] = 'b';
ret = swscanf(buffer, format2, &c);
ok(ret == 1, "swscanf returned %d\n", ret);
ok(c == 'b', "c = %x\n", c);
}
START_TEST(scanf)