about summary refs log tree commit diff
path: root/Src/builtin.c
diff options
context:
space:
mode:
authorPeter Stephenson <p.stephenson@samsung.com>2023-03-22 10:24:11 +0000
committerPeter Stephenson <p.stephenson@samsung.com>2023-03-22 10:24:11 +0000
commit6763f45e77b130fdcecd244440552095b5ee23b5 (patch)
treea69567aade0f7a2eece3383b370db633d8c51c87 /Src/builtin.c
parent9bd477dce9a5887d42a5365aaf8906ac1f118510 (diff)
downloadzsh-6763f45e77b130fdcecd244440552095b5ee23b5.tar.gz
zsh-6763f45e77b130fdcecd244440552095b5ee23b5.tar.xz
zsh-6763f45e77b130fdcecd244440552095b5ee23b5.zip
58586: print "%s" with invalid multibyte character
Treat each byte that is invalid or part of an incopmlete set as a single byte.
Diffstat (limited to 'Src/builtin.c')
-rw-r--r--Src/builtin.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/Src/builtin.c b/Src/builtin.c
index f38a54936..e4f356803 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -5329,20 +5329,21 @@ bin_print(char *name, char **args, Options ops, int func)
 #ifdef MULTIBYTE_SUPPORT
 			if (isset(MULTIBYTE)) {
 			    chars = mbrlen(ptr, lleft, &mbs);
-			    if (chars < 0) {
-				/*
-				 * Invalid/incomplete character at this
-				 * point.  Assume all the rest are a
-				 * single byte.  That's about the best we
-				 * can do.
-				 */
-				lchars += lleft;
-				lbytes = (ptr - b) + lleft;
-				break;
-			    } else if (chars == 0) {
-				/* NUL, handle as real character */
+			    /*
+			     * chars <= 0 means one of
+			     *
+			     * 0: NUL, handle as real character
+			     *
+			     * -1: MB_INVALID: Assume this is
+			     *     a single character as we do
+			     *     elsewhere in the code.
+			     *
+			     * -2: MB_INCOMPLETE: We're not waiting
+			     *     for input on this occasion, so
+			     *     just treat this as invalid.
+			     */
+			    if (chars <= 0)
 				chars = 1;
-			    }
 			}
 			else	/* use the non-multibyte code below */
 #endif