Loading...
gen/FreeBSD/vis.c Libc-1725.40.4 Libc-1534.81.1
--- Libc/Libc-1725.40.4/gen/FreeBSD/vis.c
+++ Libc/Libc-1534.81.1/gen/FreeBSD/vis.c
@@ -118,18 +118,7 @@
     (((flags) & VIS_NOLOCALE) ? iscgraph(c) : iswgraph(c))
 
 #define iswoctal(c)	(((u_char)(c)) >= L'0' && ((u_char)(c)) <= L'7')
-#ifdef __APPLE__
-/*
- * rdar://problem/108684957 - UTF-8, for instance, may define some whitespace
- * characters above the standard ASCII range, e.g., U+202F.  Based on the
- * description of VIS_CSTYLE, we should also be passing these through with their
- * default representation rather than encoding their UTF-16 equivalents.
- */
-#define iswwhite(flags, c)	(c == L' ' || c == L'\t' || c == L'\n' || \
-    (((flags) & VIS_NOLOCALE) == 0 && c > 0x7f && iswspace(c)))
-#else
 #define iswwhite(c)	(c == L' ' || c == L'\t' || c == L'\n')
-#endif
 #define iswsafe(c)	(c == L'\b' || c == BELL || c == L'\r')
 #define xtoa(c)		L"0123456789abcdef"[c]
 #define XTOA(c)		L"0123456789ABCDEF"[c]
@@ -292,7 +281,7 @@
 	uint64_t bmsk, wmsk;
 
 	iswextra = wcschr(extra, c) != NULL;
-	if (!iswextra && (ISGRAPH(flags, c) || iswwhite(flags, c) ||
+	if (!iswextra && (ISGRAPH(flags, c) || iswwhite(c) ||
 	    ((flags & VIS_SAFE) && iswsafe(c)))) {
 		*dst++ = c;
 		return dst;
@@ -379,16 +368,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 +514,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 +530,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. */