Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2009-03-17 15:16:28 +0300
committerCorinna Vinschen <corinna@vinschen.de>2009-03-17 15:16:28 +0300
commitd99179dbf3d1f5b3735a77970d004c4e280e691f (patch)
tree204f1efc080d1ea1da09bbf6f5578233a563a410 /newlib/libc/stdlib/mbstowcs_r.c
parentd70118655b0d30849c5a85e2afbb72b91e395a63 (diff)
* libc/stdlib/mbstowcs_r.c (_mbstowcs_r): Handle NULL destination
string correctly.
Diffstat (limited to 'newlib/libc/stdlib/mbstowcs_r.c')
-rw-r--r--newlib/libc/stdlib/mbstowcs_r.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/newlib/libc/stdlib/mbstowcs_r.c b/newlib/libc/stdlib/mbstowcs_r.c
index c6130b2bd..3dd73e42c 100644
--- a/newlib/libc/stdlib/mbstowcs_r.c
+++ b/newlib/libc/stdlib/mbstowcs_r.c
@@ -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;
}