OSDN Git Service

* libc/stdlib/wcstombs_r.c (_wcstombs_r): Handle invalid characters
authorcorinna <corinna>
Tue, 19 Jan 2010 21:14:53 +0000 (21:14 +0000)
committercorinna <corinna>
Tue, 19 Jan 2010 21:14:53 +0000 (21:14 +0000)
correctly also in the s==NULL case.

newlib/ChangeLog
newlib/libc/stdlib/wcstombs_r.c

index e47bb7b..281529b 100644 (file)
@@ -1,3 +1,8 @@
+2010-01-19  Corinna Vinschen  <corinna@vinschen.de>
+
+       * libc/stdlib/wcstombs_r.c (_wcstombs_r): Handle invalid characters
+       correctly also in the s==NULL case.
+
 2010-01-17  Corinna Vinschen  <corinna@vinschen.de>
 
        * libc/locale/locale.c (loadlocale): Change comments to refer to
index 7017a10..e74502f 100644 (file)
@@ -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);