fix an overflow in wcsxfrm when n==0

posix allows zero length destination
This commit is contained in:
Szabolcs Nagy 2014-01-23 03:24:54 +01:00
parent 59314304a0
commit f1471d3216

View File

@ -6,10 +6,12 @@
size_t __wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t loc)
{
size_t l = wcslen(src);
if (l >= n) {
if (l < n) {
wmemcpy(dest, src, l+1);
} else if (n) {
wmemcpy(dest, src, n-1);
dest[n-1] = 0;
} else wcscpy(dest, src);
}
return l;
}