Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH v2: 48168: Fix handling of NUL bytes in zexpandtabs multibyte version
- X-seq: zsh-workers 48202
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH v2: 48168: Fix handling of NUL bytes in zexpandtabs multibyte version
- Date: Sat, 20 Mar 2021 16:15:51 +0100
- Archived-at: <https://zsh.org/workers/48202>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2021-03/20210320151551.29509-1-mikachu%40gmail.com>
- In-reply-to: <485a976d-bcd6-4fcc-a4cc-c4e1831e9151@www.fastmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <485a976d-bcd6-4fcc-a4cc-c4e1831e9151@www.fastmail.com>
---
Src/utils.c | 5 ++++-
Test/B03print.ztst | 9 +++++----
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/Src/utils.c b/Src/utils.c
index 8fcea5362a..f8cbe65ba5 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5936,8 +5936,11 @@ zexpandtabs(const char *s, int len, int width, int startpos, FILE *fout,
memset(&mbs, 0, sizeof(mbs));
s++;
len--;
- } else if (ret == MB_INCOMPLETE) {
+ } else if (ret == MB_INCOMPLETE ||
/* incomplete at end --- assume likewise, best we've got */
+ ret == 0) {
+ /* NUL character returns 0, which would loop infinitely, so advance
+ * one byte in this case too */
s++;
len--;
} else {
diff --git a/Test/B03print.ztst b/Test/B03print.ztst
index 5634239346..d8618de7d4 100644
--- a/Test/B03print.ztst
+++ b/Test/B03print.ztst
@@ -304,15 +304,16 @@
foo=$'one\ttwo\tthree\tfour\n'
foo+=$'\tone\ttwo\tthree\tfour\n'
foo+=$'\t\tone\t\ttwo\t\tthree\t\tfour'
- print -x4 $foo
- print -X4 $foo
+ foo+='\0' # regression test for multibyte tab expand
+ print -x4 $foo | sed 's/\x00/nul/' # avoid raw nul byte in expected output below
+ print -X4 $foo | sed 's/\x00/nul/'
0:Tab expansion by print
>one two three four
> one two three four
-> one two three four
+> one two three fournul
>one two three four
> one two three four
-> one two three four
+> one two three fournul
unset foo
print -v foo once more
--
2.15.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author