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)