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.

This commit is contained in:
Alasdair Sinclair 2007-01-17 04:14:27 +00:00 committed by Alexandre Julliard
parent 9d70a6ee2c
commit 8137c094fd
2 changed files with 7 additions and 1 deletions

View file

@ -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

View file

@ -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)