From d99727bcb3f211b39421b1d738a3d3165fb82d78 Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Wed, 23 Dec 2015 01:14:28 +0300 Subject: [PATCH] msvcrt: Fix char to int promotion that breaks pattern lookup. Signed-off-by: Nikolay Sivov Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/msvcrt/scanf.h | 8 ++++++++ dlls/msvcrt/tests/scanf.c | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 9322704d9e8..5bf91a622f4 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -68,7 +68,11 @@ #undef _EOF_ #define _EOF_ 0 #ifdef STRING_LEN +#ifdef WIDE_CHAR #define _GETC_(file) (consumed==length ? '\0' : (consumed++, *file++)) +#else /* WIDE_CHAR */ +#define _GETC_(file) (consumed==length ? '\0' : (consumed++, (unsigned char)*file++)) +#endif /* WIDE_CHAR */ #define _UNGETC_(nch, file) do { file--; consumed--; } while(0) #define _LOCK_FILE_(file) do {} while(0) #define _UNLOCK_FILE_(file) do {} while(0) @@ -86,7 +90,11 @@ #endif /* SECURE */ #endif /* WIDE_SCANF */ #else /* STRING_LEN */ +#ifdef WIDE_CHAR #define _GETC_(file) (consumed++, *file++) +#else /* WIDE_CHAR */ +#define _GETC_(file) (consumed++, (unsigned char)*file++) +#endif /* WIDE_CHAR */ #define _UNGETC_(nch, file) do { file--; consumed--; } while(0) #define _LOCK_FILE_(file) do {} while(0) #define _UNLOCK_FILE_(file) do {} while(0) diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 3c5a05e68a5..6cb85facaf6 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -244,6 +244,13 @@ static void test_sscanf( void ) ret = sscanf(buffer, "%d:%d%n", &hour, &min, &number_so_far); ok(ret == 2, "Wrong number of arguments read: %d\n", ret); ok(number_so_far == 4, "%%n yielded wrong result: %d\n", number_so_far); + + buffer[0] = 0; + buffer1[0] = 0; + ret = sscanf("test=value\xda", "%[^=] = %[^;]", buffer, buffer1); + ok(ret == 2, "got %d\n", ret); + ok(!strcmp(buffer, "test"), "buf %s\n", buffer); + ok(!strcmp(buffer1, "value\xda"), "buf %s\n", buffer1); } static void test_sscanf_s(void)