Ensure that the {,v}swprintf functions always null-terminate the
output string, even if an encoding error or malloc failure occurs.
This commit is contained in:
parent
9da846a0f4
commit
8595324df3
@ -66,6 +66,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale,
|
||||
f._bf._base = f._p = (unsigned char *)malloc(128);
|
||||
if (f._bf._base == NULL) {
|
||||
errno = ENOMEM;
|
||||
*s = L'\0';
|
||||
return (-1);
|
||||
}
|
||||
f._bf._size = f._w = 127; /* Leave room for the NUL */
|
||||
@ -74,6 +75,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale,
|
||||
sverrno = errno;
|
||||
free(f._bf._base);
|
||||
errno = sverrno;
|
||||
*s = L'\0';
|
||||
return (-1);
|
||||
}
|
||||
*f._p = '\0';
|
||||
@ -87,6 +89,7 @@ vswprintf_l(wchar_t * __restrict s, size_t n, locale_t locale,
|
||||
free(f._bf._base);
|
||||
if (nwc == (size_t)-1) {
|
||||
errno = EILSEQ;
|
||||
*s = L'\0';
|
||||
return (-1);
|
||||
}
|
||||
if (nwc == n) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user