diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2010-01-19 21:14:53 +0000 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2010-01-19 21:14:53 +0000 |
commit | 8c72ebb7e01640ea1916fa2637f20c0dab38e633 (patch) | |
tree | 5151a96a1b54bb90eb67187848b9eb6db9426650 /newlib/libc/stdlib | |
parent | 2a2b1437e7179a2b194136bbc03fd8cf95eefdbf (diff) | |
download | cygnal-8c72ebb7e01640ea1916fa2637f20c0dab38e633.tar.gz cygnal-8c72ebb7e01640ea1916fa2637f20c0dab38e633.tar.bz2 cygnal-8c72ebb7e01640ea1916fa2637f20c0dab38e633.zip |
* libc/stdlib/wcstombs_r.c (_wcstombs_r): Handle invalid characters
correctly also in the s==NULL case.
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/wcstombs_r.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/newlib/libc/stdlib/wcstombs_r.c b/newlib/libc/stdlib/wcstombs_r.c index 7017a10b1..e74502f46 100644 --- a/newlib/libc/stdlib/wcstombs_r.c +++ b/newlib/libc/stdlib/wcstombs_r.c @@ -13,20 +13,25 @@ _DEFUN (_wcstombs_r, (reent, s, pwcs, n, state), char *ptr = s; size_t max = n; char buff[8]; - int i, num_to_copy; + int i, bytes, num_to_copy; if (s == NULL) { size_t num_bytes = 0; while (*pwcs != 0) - num_bytes += __wctomb (r, buff, *pwcs++, __locale_charset (), state); + { + bytes = __wctomb (r, buff, *pwcs++, __locale_charset (), state); + if (bytes == -1) + return -1; + num_bytes += bytes; + } return num_bytes; } else { while (n > 0) { - int bytes = __wctomb (r, buff, *pwcs, __locale_charset (), state); + bytes = __wctomb (r, buff, *pwcs, __locale_charset (), state); if (bytes == -1) return -1; num_to_copy = (n > bytes ? bytes : (int)n); |