Fix EOVERFLOW detection in vswprintf(3)

Reviewed by:	tjr
MFC after:	2 weeks
This commit is contained in:
Max Khon 2005-02-21 19:41:44 +00:00
parent adec44c08b
commit f1defde9d5

View File

@ -49,6 +49,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
struct __sFILEX ext;
char *mbp;
int ret, sverrno;
size_t nwc;
if (n == 0) {
errno = EINVAL;
@ -79,13 +80,13 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt,
* fputwc() did in __vfwprintf().
*/
mbs = initial;
if (mbsrtowcs(s, (const char **)&mbp, n, &mbs) == (size_t)-1) {
free(f._bf._base);
nwc = mbsrtowcs(s, (const char **)&mbp, n, &mbs);
free(f._bf._base);
if (nwc == (size_t)-1) {
errno = EILSEQ;
return (-1);
}
free(f._bf._base);
if (s[n - 1] != L'\0') {
if (nwc == n) {
s[n - 1] = L'\0';
errno = EOVERFLOW;
return (-1);