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:
-rw-r--r--newlib/ChangeLog5
-rw-r--r--newlib/libc/stdlib/mbstowcs_r.c20
2 files changed, 17 insertions, 8 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 18a86162c..5e84cb47d 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -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.
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;
}