Fix wscanf family positional parameter handling in %lc, %ls, %l[]

* libc/stdio/vfwscanf.c (__SVFWSCANF_R): Convert wrong usage of va_arg
        to GET_ARG in %lc, %ls nad %l[] cases.  Fix unterminated string in %l[]
        case.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Shoichi Sakon 2015-08-03 21:51:16 +02:00 committed by Corinna Vinschen
parent 09d458b5c7
commit 001ef5af39
2 changed files with 15 additions and 7 deletions

View File

@ -1,3 +1,9 @@
2015-08-03 Shoichi Sakon <s-sakon@ap.jp.nec.com>
* libc/stdio/vfwscanf.c (__SVFWSCANF_R): Convert wrong usage of va_arg
to GET_ARG in %lc, %ls nad %l[] cases. Fix unterminated string in %l[]
case.
2015-07-30 Sebastian Huber <sebastian.huber@embedded-brains.de> 2015-07-30 Sebastian Huber <sebastian.huber@embedded-brains.de>
* libc/sys/rtems/include/sys/lock.h (__LOCK_INIT_RECURSIVE): Use * libc/sys/rtems/include/sys/lock.h (__LOCK_INIT_RECURSIVE): Use

View File

@ -777,7 +777,7 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
if (flags & LONG) if (flags & LONG)
{ {
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
p = va_arg(ap, wchar_t *); p = GET_ARG(N, ap, wchar_t *);
n = 0; n = 0;
while (width-- != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF) while (width-- != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF)
{ {
@ -794,7 +794,7 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
else else
{ {
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *); mbp = GET_ARG(N, ap, char *);
n = 0; n = 0;
memset ((_PTR)&mbs, '\0', sizeof (mbstate_t)); memset ((_PTR)&mbs, '\0', sizeof (mbstate_t));
while (width != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF) while (width != 0 && (wi = _fgetwc_r (rptr, fp)) != WEOF)
@ -849,7 +849,7 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
} }
else if (flags & LONG) else if (flags & LONG)
{ {
p0 = p = va_arg(ap, wchar_t *); p0 = p = GET_ARG(N, ap, wchar_t *);
while ((wi = _fgetwc_r (rptr, fp)) != WEOF while ((wi = _fgetwc_r (rptr, fp)) != WEOF
&& width-- != 0 && INCCL (wi)) && width-- != 0 && INCCL (wi))
*p++ = (wchar_t) wi; *p++ = (wchar_t) wi;
@ -858,11 +858,13 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
n = p - p0; n = p - p0;
if (n == 0) if (n == 0)
goto match_failure; goto match_failure;
*p = L'\0';
nassigned++;
} }
else else
{ {
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *); mbp = GET_ARG(N, ap, char *);
n = 0; n = 0;
memset ((_PTR) &mbs, '\0', sizeof (mbstate_t)); memset ((_PTR) &mbs, '\0', sizeof (mbstate_t));
while ((wi = _fgetwc_r (rptr, fp)) != WEOF while ((wi = _fgetwc_r (rptr, fp)) != WEOF
@ -914,7 +916,7 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
} }
else if (flags & LONG) else if (flags & LONG)
{ {
p0 = p = va_arg(ap, wchar_t *); p0 = p = GET_ARG(N, ap, wchar_t *);
while ((wi = _fgetwc_r (rptr, fp)) != WEOF while ((wi = _fgetwc_r (rptr, fp)) != WEOF
&& width-- != 0 && !iswspace (wi)) && width-- != 0 && !iswspace (wi))
{ {
@ -923,13 +925,13 @@ _DEFUN(__SVFWSCANF_R, (rptr, fp, fmt0, ap),
} }
if (wi != WEOF) if (wi != WEOF)
_ungetwc_r (rptr, wi, fp); _ungetwc_r (rptr, wi, fp);
*p = '\0'; *p = L'\0';
nassigned++; nassigned++;
} }
else else
{ {
if (!(flags & SUPPRESS)) if (!(flags & SUPPRESS))
mbp = va_arg(ap, char *); mbp = GET_ARG(N, ap, char *);
memset ((_PTR) &mbs, '\0', sizeof (mbstate_t)); memset ((_PTR) &mbs, '\0', sizeof (mbstate_t));
while ((wi = _fgetwc_r (rptr, fp)) != WEOF while ((wi = _fgetwc_r (rptr, fp)) != WEOF
&& width != 0 && !iswspace (wi)) && width != 0 && !iswspace (wi))