Piotr Caban : msvcrt: Fix wide characters handling in wscanf functions.
Alexandre Julliard
julliard at winehq.org
Mon Apr 3 14:01:47 CDT 2017
Module: wine
Branch: master
Commit: e7f9b562b9da5aa1fbe369f9e57fe63d08cbb743
URL: http://source.winehq.org/git/wine.git/?a=commit;h=e7f9b562b9da5aa1fbe369f9e57fe63d08cbb743
Author: Piotr Caban <piotr at codeweavers.com>
Date: Mon Apr 3 12:45:58 2017 +0200
msvcrt: Fix wide characters handling in wscanf functions.
Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/msvcrt/scanf.h | 16 ++++++++--------
dlls/msvcrt/tests/scanf.c | 12 +++++++++++-
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h
index 0fa1e6f..2920b9b 100644
--- a/dlls/msvcrt/scanf.h
+++ b/dlls/msvcrt/scanf.h
@@ -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;
}
diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c
index ecb270b..1d1f28e 100644
--- a/dlls/msvcrt/tests/scanf.c
+++ b/dlls/msvcrt/tests/scanf.c
@@ -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)
More information about the wine-cvs
mailing list