* libc/stdlib/mbstowcs_r.c (_mbstowcs_r): Handle NULL destination

string correctly.
This commit is contained in:
Corinna Vinschen 2009-03-17 12:16:28 +00:00
parent d70118655b
commit d99179dbf3
2 changed files with 17 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2009-03-17 Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/mbstowcs_r.c (_mbstowcs_r): Handle NULL destination
string correctly.
2009-03-16 Mark Mitchell <mark@codesourcery.com>
* libc/machine/arm/strlen.c (strlen): Fix defect in Thumb-2 mode.

View File

@ -9,25 +9,29 @@ _DEFUN (_mbstowcs_r, (reent, pwcs, s, n, state),
size_t n _AND
mbstate_t *state)
{
wchar_t *ptr = pwcs;
size_t max = n;
size_t ret = 0;
char *t = (char *)s;
int bytes;
if (!pwcs)
n = (size_t) 1; /* Value doesn't matter as long as it's not 0. */
while (n > 0)
{
bytes = _mbtowc_r (r, ptr, t, MB_CUR_MAX, state);
bytes = _mbtowc_r (r, pwcs, t, MB_CUR_MAX, state);
if (bytes < 0)
{
state->__count = 0;
return -1;
}
else if (bytes == 0)
return ptr - pwcs;
break;
t += bytes;
++ptr;
--n;
++ret;
if (pwcs)
{
++pwcs;
--n;
}
}
return max;
return ret;
}