From: Piotr Caban Subject: Re: [PATCH] msvcrt: Fix fscanf return when EOF is immediately after an end of line. Message-Id: <5bcb4ab2-17a0-0d14-4ca0-73c4b7094991@gmail.com> Date: Thu, 17 Oct 2019 13:22:00 +0200 In-Reply-To: References: Hi Erich, The implementation part of the patch doesn't look right. I think that it should be fixed by %s format reporting error when there's no characters to read. I'm attaching a diff (generated on top of your patch) that shows the problems. Also please use only tests on strings (sscanf) or handle file creation failure. Thanks, Piotr diff --git a/dlls/msvcrt/tests/scanf.c b/dlls/msvcrt/tests/scanf.c index c0d5aa66d1..4759ba291c 100644 --- a/dlls/msvcrt/tests/scanf.c +++ b/dlls/msvcrt/tests/scanf.c @@ -27,7 +27,7 @@ static void test_fscanf( void ) static const char file_name[] = "fprintf.tst"; static const char contents[] = "line1\n" - "line2\n" + "line2 " ; char buf[1024]; FILE *fp; @@ -77,6 +77,14 @@ static void test_sscanf( void ) ret = p_sscanf(buffer, "%d", &result); ok( ret == EOF,"sscanf returns %x instead of %x\n", ret, EOF ); + ret = p_sscanf(" \t\n\n", "%s", buffer); + ok(ret == -1, "ret = %d\n", ret); + + buffer1[0] = 'a'; + ret = p_sscanf("test\n", "%s%c", buffer, buffer1); + ok(ret == 2, "ret = %d\n", ret); + ok(buffer1[0] == '\n', "buffer1[0] = %d\n", buffer1[0]); + /* check %p */ ok( p_sscanf("000000000046F170", "%p", &ptr) == 1, "sscanf failed\n" ); ok( ptr == (void *)0x46F170,"sscanf reads %p instead of %x\n", ptr, 0x46F170 );