summary refs log tree commit diff
path: root/wcsmbs/mbsrtowcs.c
diff options
context:
space:
mode:
Diffstat (limited to 'wcsmbs/mbsrtowcs.c')
-rw-r--r--wcsmbs/mbsrtowcs.c23
1 files changed, 7 insertions, 16 deletions
diff --git a/wcsmbs/mbsrtowcs.c b/wcsmbs/mbsrtowcs.c
index 8f9efb3285..9172fd9ede 100644
--- a/wcsmbs/mbsrtowcs.c
+++ b/wcsmbs/mbsrtowcs.c
@@ -19,6 +19,7 @@
 
 #include <errno.h>
 #include <gconv.h>
+#include <stdlib.h>
 #include <string.h>
 #include <wchar.h>
 #include <wcsmbsload.h>
@@ -55,22 +56,16 @@ __mbsrtowcs (dst, src, len, ps)
   if (dst == NULL)
     {
       wchar_t buf[64];		/* Just an arbitrary size.  */
-      size_t inbytes_in = strlen (*src) + 1;
-      size_t inbytes = inbytes_in;
+      const char *srcend = *src + strlen (*src) + 1;
       const char *inbuf = *src;
       size_t written;
 
       data.outbuf = (char *) buf;
-      data.outbufsize = sizeof (buf);
+      data.outbufend = data.outbuf + sizeof (buf);
       do
 	{
-	  inbuf += inbytes_in - inbytes;
-	  inbytes_in = inbytes;
-	  data.outbufavail = 0;
-	  written = 0;
-
 	  status = (*__wcsmbs_gconv_fcts.towc->fct) (__wcsmbs_gconv_fcts.towc,
-						     &data, inbuf, &inbytes,
+						     &data, &inbuf, srcend,
 						     &written, 0);
 	  result += written;
 	}
@@ -86,15 +81,13 @@ __mbsrtowcs (dst, src, len, ps)
       /* This code is based on the safe assumption that all internal
 	 multi-byte encodings use the NUL byte only to mark the end
 	 of the string.  */
-      size_t inbytes_in = __strnlen (*src, len * MB_CUR_MAX) + 1;
-      size_t inbytes = inbytes_in;
+      const char *srcend = *src + __strnlen (*src, len * MB_CUR_MAX) + 1;
 
       data.outbuf = (char *) dst;
-      data.outbufsize = len * sizeof (wchar_t);
-      data.outbufavail = 0;
+      data.outbufend = data.outbuf + len * sizeof (wchar_t);
 
       status = (*__wcsmbs_gconv_fcts.towc->fct) (__wcsmbs_gconv_fcts.towc,
-						 &data, *src, &inbytes,
+						 &data, src, srcend,
 						 &result, 0);
 
       /* We have to determine whether the last character converted
@@ -107,8 +100,6 @@ __mbsrtowcs (dst, src, len, ps)
 	  *src = NULL;
 	  --result;
 	}
-      else
-	*src += inbytes_in - inbytes;
     }
 
   /* There must not be any problems with the conversion but illegal input