Loading...
gen/FreeBSD/vis.c Libc-1725.40.4 Libc-1583.0.14
--- Libc/Libc-1725.40.4/gen/FreeBSD/vis.c
+++ Libc/Libc-1583.0.14/gen/FreeBSD/vis.c
@@ -379,16 +379,14 @@
 istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
     int flags, const char *mbextra, int *cerr_ptr)
 {
-	char mbbuf[MB_CUR_MAX];
 	wchar_t *dst, *src, *pdst, *psrc, *start, *extra;
 	size_t len, olen;
 	uint64_t bmsk, wmsk;
 	wint_t c;
 	visfun_t f;
 	int clen = 0, cerr, error = -1, i, shft;
-	char *mbdst, *mbwrite, *mdst;
-	ssize_t mbslength;
-	size_t maxolen;
+	char *mbdst, *mdst;
+	ssize_t mbslength, maxolen;
 	mbstate_t mbstate;
 
 	_DIAGASSERT(mbdstp != NULL);
@@ -527,33 +525,8 @@
 	olen = 0;
 	bzero(&mbstate, sizeof(mbstate));
 	for (dst = start; len > 0; len--) {
-		if (!cerr) {
-			/*
-			 * If we have at least MB_CUR_MAX bytes in the buffer,
-			 * we'll just do the conversion in-place into mbdst.  We
-			 * need to be a little more conservative when we get to
-			 * the end of the buffer, as we may not have MB_CUR_MAX
-			 * bytes but we may not need it.
-			 */
-			if (maxolen - olen > MB_CUR_MAX)
-				mbwrite = mbdst;
-			else
-				mbwrite = mbbuf;
-			clen = wcrtomb(mbwrite, *dst, &mbstate);
-			if (clen > 0 && mbwrite != mbdst) {
-				/*
-				 * Don't break past our output limit, noting
-				 * that maxolen includes the nul terminator so
-				 * we can't write past maxolen - 1 here.
-				 */
-				if (olen + clen >= maxolen) {
-					errno = ENOSPC;
-					goto out;
-				}
-
-				memcpy(mbdst, mbwrite, clen);
-			}
-		}
+		if (!cerr)
+			clen = wcrtomb(mbdst, *dst, &mbstate);
 		if (cerr || clen < 0) {
 			/*
 			 * Conversion error, process as a byte(s) instead.
@@ -568,27 +541,16 @@
 				shft = i * NBBY;
 				bmsk = (uint64_t)0xffLL << shft;
 				wmsk |= bmsk;
-				if ((*dst & wmsk) || i == 0) {
-					if (olen + clen + 1 >= maxolen) {
-						errno = ENOSPC;
-						goto out;
-					}
-
+				if ((*dst & wmsk) || i == 0)
 					mbdst[clen++] = (char)(
 					    (uint64_t)(*dst & bmsk) >>
 					    shft);
-				}
 			}
 			cerr = 1;
 		}
-
-		/*
-		 * We'll be dereferencing mbdst[clen] after this to write the
-		 * nul terminator; the above paths should have checked for a
-		 * possible overflow already.
-		 */
-		assert(olen + clen < maxolen);
-
+		/* If this character would exceed our output limit, stop. */
+		if (olen + clen > (size_t)maxolen)
+			break;
 		/* Advance output pointer by number of bytes written. */
 		mbdst += clen;
 		/* Advance buffer character pointer. */