diff options
author | fjoe <fjoe@FreeBSD.org> | 2005-02-21 19:41:44 +0000 |
---|---|---|
committer | fjoe <fjoe@FreeBSD.org> | 2005-02-21 19:41:44 +0000 |
commit | 8a1314cd3e8d80aee45d9802c39446568f63bd33 (patch) | |
tree | d82c1c0c536c43cab9ef7de903a3b5bfa26be8f8 /lib/libc/stdio/vswprintf.c | |
parent | 347e711324e9ae325aab0cf7acf20e93db5c8cc8 (diff) | |
download | FreeBSD-src-8a1314cd3e8d80aee45d9802c39446568f63bd33.zip FreeBSD-src-8a1314cd3e8d80aee45d9802c39446568f63bd33.tar.gz |
Fix EOVERFLOW detection in vswprintf(3)
Reviewed by: tjr
MFC after: 2 weeks
Diffstat (limited to 'lib/libc/stdio/vswprintf.c')
-rw-r--r-- | lib/libc/stdio/vswprintf.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c index 77e289d..1d8a64e 100644 --- a/lib/libc/stdio/vswprintf.c +++ b/lib/libc/stdio/vswprintf.c @@ -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); |