Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: read -d $'\200' doesn't work with set +o multibyte (and [PATCH])
> 2022/12/10 18:06, Stephane Chazelas <stephane@xxxxxxxxxxxx> wrote:
> It works better after:
>
> diff --git a/Src/builtin.c b/Src/builtin.c
> index a7b7755a7..d650ca750 100644
> --- a/Src/builtin.c
> +++ b/Src/builtin.c
> @@ -6414,9 +6414,9 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
> delim = (wchar_t)wi;
> else
> delim = (wchar_t)((delimstr[0] == Meta) ?
> - delimstr[1] ^ 32 : delimstr[0]);
> + STOUC(delimstr[1]) ^ 32 : STOUC(delimstr[0]));
> #else
> - delim = (delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0];
> + delim = (delimstr[0] == Meta) ? STOUC(delimstr[1]) ^ 32 : STOUC(delimstr[0]);
> #endif
> if (SHTTY != -1) {
> struct ttyinfo ti;
>
(snip)
> So I guess that's the fix for my bug.
Thanks, I think it fixes the problem for the '#ifdef MULTIBYTE_SUPPORT' section.
When MULTIBYTE_SUPPORT is not defined, delim is char, so we need
STOUC() not when assigning to delim but when using delim.
But instead of adding STOUC() to every use of delim (in nondef
MULTIBYTE_SUPPORT section), it would be easier to define delim as int.
A simple test is added (it only tests the C locale with multibyte option on).
diff --git a/Src/builtin.c b/Src/builtin.c
index a7b7755a7..a6fadb622 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -6286,7 +6286,7 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
char *laststart;
size_t ret;
#else
- char delim = '\n';
+ int delim = '\n';
#endif
if (OPT_HASARG(ops,c='k')) {
@@ -6413,10 +6413,10 @@ bin_read(char *name, char **args, Options ops, UNUSED(int func))
if (wi != WEOF)
delim = (wchar_t)wi;
else
- delim = (wchar_t)((delimstr[0] == Meta) ?
+ delim = (wchar_t)STOUC((delimstr[0] == Meta) ?
delimstr[1] ^ 32 : delimstr[0]);
#else
- delim = (delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0];
+ delim = STOUC((delimstr[0] == Meta) ? delimstr[1] ^ 32 : delimstr[0]);
#endif
if (SHTTY != -1) {
struct ttyinfo ti;
diff --git a/Test/B04read.ztst b/Test/B04read.ztst
index 25c3d4173..a2f03c9b3 100644
--- a/Test/B04read.ztst
+++ b/Test/B04read.ztst
@@ -82,6 +82,12 @@
>Testing the
>null hypothesis
+ print -n $'first line\x80second line\x80' |
+ while read -d $'\x80' line; do print $line; done
+0:read with a delimeter >= 0x80
+>first line
+>second line
+
# Note that trailing NULLs are not stripped even if they are in
# $IFS; only whitespace characters contained in $IFS are stripped.
print -n $'Aaargh, I hate nulls.\0\0\0' | read line
Messages sorted by:
Reverse Date,
Date,
Thread,
Author