This is the mail archive of the
newlib@sources.redhat.com
mailing list for the newlib project.
vfprintf wide char print fix
- From: "Artem B. Bityuckiy" <abityuckiy at yandex dot ru>
- To: newlib at sources dot redhat dot com
- Cc: "Artem B. Bityuckiy" <abitytsky at softminecorp dot com>
- Date: Fri, 30 Apr 2004 16:43:26 +0400
- Subject: vfprintf wide char print fix
Hello. Here is the patch that fixes vfprintf's behavior if error occurs
when converting wide characters/strings to multi-byte characters/strings
(when %C, %S, %lc, %ls format modifiers are used).
Without this patch vfprintf doesn't return EOF as it must do.
--
Best Regards,
Artem B. Bityuckiy,
St.-Petersburg, Russia.
Index: vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.31
diff -c -r1.31 vfprintf.c
*** vfprintf.c 23 Apr 2004 21:44:22 -0000 1.31
--- vfprintf.c 30 Apr 2004 12:37:34 -0000
***************
*** 762,769 ****
memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
if ((size = (int)_wcrtomb_r (data, cp,
(wchar_t)GET_ARG (N, ap, wint_t),
! &ps)) == -1)
goto error;
}
else {
*cp = GET_ARG (N, ap, int);
--- 762,771 ----
memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
if ((size = (int)_wcrtomb_r (data, cp,
(wchar_t)GET_ARG (N, ap, wint_t),
! &ps)) == -1) {
! fp->_flags |= __SERR;
goto error;
+ }
}
else {
*cp = GET_ARG (N, ap, int);
***************
*** 942,949 ****
if (wcp[m] == L'\0')
break;
if ((n = (int)_wcrtomb_r (data,
! buf, wcp[m], &ps)) == -1)
goto error;
if (n + size > prec)
break;
m += 1;
--- 944,953 ----
if (wcp[m] == L'\0')
break;
if ((n = (int)_wcrtomb_r (data,
! buf, wcp[m], &ps)) == -1) {
! fp->_flags |= __SERR;
goto error;
+ }
if (n + size > prec)
break;
m += 1;
***************
*** 954,961 ****
}
else {
if ((size = (int)_wcsrtombs_r (data,
! NULL, &wcp, 0, &ps)) == -1)
! goto error;
wcp = (_CONST wchar_t *)cp;
}
--- 958,967 ----
}
else {
if ((size = (int)_wcsrtombs_r (data,
! NULL, &wcp, 0, &ps)) == -1) {
! fp->_flags |= __SERR;
! goto error;
! }
wcp = (_CONST wchar_t *)cp;
}
***************
*** 963,976 ****
break;
if ((malloc_buf =
! (char *)_malloc_r (data, size + 1)) == NULL)
goto error;
/* Convert widechar string to multibyte string. */
memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
if (_wcsrtombs_r (data, malloc_buf,
! &wcp, size, &ps) != size)
goto error;
cp = malloc_buf;
cp[size] = '\0';
}
--- 969,986 ----
break;
if ((malloc_buf =
! (char *)_malloc_r (data, size + 1)) == NULL) {
! fp->_flags |= __SERR;
goto error;
+ }
/* Convert widechar string to multibyte string. */
memset ((_PTR)&ps, '\0', sizeof (mbstate_t));
if (_wcsrtombs_r (data, malloc_buf,
! &wcp, size, &ps) != size) {
! fp->_flags |= __SERR;
goto error;
+ }
cp = malloc_buf;
cp[size] = '\0';
}