From 6763f45e77b130fdcecd244440552095b5ee23b5 Mon Sep 17 00:00:00 2001
From: Peter Stephenson
Date: Wed, 22 Mar 2023 10:24:11 +0000
Subject: 58586: print "%s" with invalid multibyte character
Treat each byte that is invalid or part of an incopmlete set as a single byte.
---
Src/builtin.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
(limited to 'Src/builtin.c')
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
--
cgit 1.4.1