Commit 638c8e38 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Don't overwrite unmatched string in scanf.

parent 7341996f
...@@ -478,7 +478,7 @@ _FUNCTION_ { ...@@ -478,7 +478,7 @@ _FUNCTION_ {
if (width>0) width--; if (width>0) width--;
} }
/* terminate */ /* terminate */
if (!suppress) *sptr = 0; if (st && !suppress) *sptr = 0;
} }
break; break;
widecharstring: { /* read a word into a wchar_t* */ widecharstring: { /* read a word into a wchar_t* */
...@@ -508,7 +508,7 @@ _FUNCTION_ { ...@@ -508,7 +508,7 @@ _FUNCTION_ {
if (width>0) width--; if (width>0) width--;
} }
/* terminate */ /* terminate */
if (!suppress) *sptr = 0; if (st && !suppress) *sptr = 0;
} }
break; break;
/* 'c' and 'C work analogously to 's' and 'S' as described /* 'c' and 'C work analogously to 's' and 'S' as described
......
...@@ -131,6 +131,13 @@ static void test_sscanf( void ) ...@@ -131,6 +131,13 @@ static void test_sscanf( void )
ok( ret == 1, "Error with format \"%s\"\n","%*[a-cd-dg-e]%c"); ok( ret == 1, "Error with format \"%s\"\n","%*[a-cd-dg-e]%c");
ok( buffer[0] == 'h', "Error with \"abcefgdh\" \"%c\"\n", buffer[0]); ok( buffer[0] == 'h', "Error with \"abcefgdh\" \"%c\"\n", buffer[0]);
buffer1[0] = 'b';
ret = sscanf("a","%s%s", buffer, buffer1);
ok( ret == 1, "expected 1, got %u\n", ret);
ok( buffer[0] == 'a', "buffer[0] = '%c'\n", buffer[0]);
ok( buffer[1] == '\0', "buffer[1] = '%c'\n", buffer[1]);
ok( buffer1[0] == 'b', "buffer1[0] = '%c'\n", buffer1[0]);
/* check digits */ /* check digits */
ret = sprintf(buffer,"%d:%d:%d",hour,min,sec); ret = sprintf(buffer,"%d:%d:%d",hour,min,sec);
ok( ret == 8, "expected 8, got %u\n", ret); ok( ret == 8, "expected 8, got %u\n", ret);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment