From 8137c094fdf37e9d101e52f114103bda55c5b3ac Mon Sep 17 00:00:00 2001 From: Alasdair Sinclair Date: Wed, 17 Jan 2007 04:14:27 +0000 Subject: [PATCH] msvcrt: If we're at EOF in the buffer and we have pattern %n in format string we should not count the EOF in the total. --- dlls/msvcrt/scanf.h | 2 +- dlls/msvcrt/tests/scanf.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/dlls/msvcrt/scanf.h b/dlls/msvcrt/scanf.h index 139f1426e10..7fe3cc4de49 100644 --- a/dlls/msvcrt/scanf.h +++ b/dlls/msvcrt/scanf.h @@ -415,7 +415,7 @@ _FUNCTION_ { case 'n': { if (!suppress) { int*n = va_arg(ap, int*); - *n = consumed - (nch!=_EOF_); + *n = consumed - 1; } /* This is an odd one: according to the standard, * "Execution of a %n directive does not increment the diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index 71e6e228077..65bea469036 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -162,6 +162,12 @@ static void test_sscanf( void ) ok(strcmp(buffer1,"def")==0, "Second %%s read incorrectly: %s\n", buffer1); ok(number_so_far==6, "%%n yielded wrong result: %d\n", number_so_far); ok(ret == 2, "%%n shouldn't count as a conversion: %d\n", ret); + + /* Check where %n matches to EOF in buffer */ + strcpy(buffer, "3:45"); + 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); } START_TEST(scanf)