diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Src/builtin.c | 27 |
2 files changed, 20 insertions, 13 deletions
diff --git a/ChangeLog b/ChangeLog index ec32f1029..c575a0b3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2023-03-22 Peter Stephenson <p.stephenson@samsung.com> + + * 51586: Src/builtin.c: When printf "%s" encounters a byte + that's not part of a vaild multibyte character it should handle + it a single byte at a time. + 2023-03-16 Oliver Kiddle <opk@zsh.org> * 51583: Completion/Unix/Command/_git: update completion of 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 |