diff options
author | tjr <tjr@FreeBSD.org> | 2002-09-26 08:26:16 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-09-26 08:26:16 +0000 |
commit | e9dc19237215f59529ac3c4dbd7dd60561743329 (patch) | |
tree | 76aba0569af51b16ed123e1a44824456ffadecdb /lib/libc/stdio/vswprintf.c | |
parent | aecdb4ddca551dbce73b6783fe3cf6fb5ecd9aa1 (diff) | |
download | FreeBSD-src-e9dc19237215f59529ac3c4dbd7dd60561743329.zip FreeBSD-src-e9dc19237215f59529ac3c4dbd7dd60561743329.tar.gz |
Correctly handle the case where __vfwprintf() fails because it runs out
of memory.
Diffstat (limited to 'lib/libc/stdio/vswprintf.c')
-rw-r--r-- | lib/libc/stdio/vswprintf.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/libc/stdio/vswprintf.c b/lib/libc/stdio/vswprintf.c index da5c4c2..3ea1b4c 100644 --- a/lib/libc/stdio/vswprintf.c +++ b/lib/libc/stdio/vswprintf.c @@ -48,7 +48,7 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, mbstate_t mbs; char *mbp; size_t mbresult; - int ret; + int ret, sverrno; if (n == 0) { errno = EINVAL; @@ -66,6 +66,12 @@ vswprintf(wchar_t * __restrict s, size_t n, const wchar_t * __restrict fmt, f._extra = &ext; INITEXTRA(&f); ret = __vfwprintf(&f, fmt, ap); + if (ret < 0) { + sverrno = errno; + free(f._bf._base); + errno = sverrno; + return (-1); + } *f._p = '\0'; mbp = f._bf._base; memset(&mbs, 0, sizeof(mbs)); |