msvcrt: Update size checks for secure scanf versions.

Signed-off-by: Michał Janiszewski <janisozaur@gmail.com>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Michał Janiszewski 2018-07-09 14:45:28 +02:00 committed by Alexandre Julliard
parent bab5a703da
commit 08d98f0ff8
2 changed files with 10 additions and 3 deletions

View File

@ -548,13 +548,13 @@ _FUNCTION_ {
while (width && (nch != _EOF_))
{
if (!suppress) {
*str++ = _CHAR2SUPPORTED_(nch);
if(size) size--;
else {
_UNLOCK_FILE_(file);
*pstr = 0;
return rd;
}
*str++ = _CHAR2SUPPORTED_(nch);
}
st++;
width--;
@ -574,13 +574,13 @@ _FUNCTION_ {
while (width && (nch != _EOF_))
{
if (!suppress) {
*str++ = _WIDE2SUPPORTED_(nch);
if(size) size--;
else {
_UNLOCK_FILE_(file);
*pstr = 0;
return rd;
}
*str++ = _WIDE2SUPPORTED_(nch);
}
st++;
width--;

View File

@ -282,10 +282,17 @@ static void test_sscanf_s(void)
ok(ret == 0, "Wrong number of arguments read: %d\n", ret);
ok(buf[0]=='\0', "buf = %s\n", buf);
buf[0] = 'a';
memset(buf, 'a', sizeof(buf));
ret = psscanf_s("123", "%3c", buf, 2);
ok(ret == 0, "Wrong number of arguments read: %d\n", ret);
ok(buf[0]=='\0', "buf = %s\n", buf);
ok(buf[1]=='2', "buf[1] = %d\n", buf[1]);
ok(buf[2]=='a', "buf[2] = %d\n", buf[2]);
buf[3] = 'a';
buf[4] = 0;
ret = psscanf_s("123", "%3c", buf, 3);
ok(!strcmp("123a", buf), "buf = %s\n", buf);
i = 1;
ret = psscanf_s("123 123", "%s %d", buf, 2, &i);