From: "Jun. T" <takimoto-j@kba.biglobe.ne.jp>
To: zsh-workers@zsh.org
Subject: Re: (LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C)
Date: Thu, 7 Sep 2023 23:26:55 +0900 [thread overview]
Message-ID: <EBF09792-A011-44F6-A36C-8F704A1A1FF8@kba.biglobe.ne.jp> (raw)
In-Reply-To: <88812889-04BC-412A-85BE-BDAA2326B29B@kba.biglobe.ne.jp>
> 2023/09/01 2:38, I wrote:
>
> So we need to reset (or save/restore) errflag somewhere...
The patch below is a simple save/restore errflag. It seems to work,
but I'm not sure it is the (or a) correct fix. I will not push this
unless I get positive responses.
By the way, the problem is not limited to the C locale. Even with
UTF-8 locale (tested on Linux. macOS may behave differently):
% a=( 0x8000_0000 0x8000_0001 )
% printf "%s\n" ${(#)a} | hexdump -C
00000000 22 0a 22 |"."|
00000003
Another problem (but I feel we don't need to fix it) is that
when we get error with the (X) flag seems to be rather arbitrary.
For positive values the lowest 4 bytes are used (subst.c:1503),
while for negative values only the lowest one byte is used
(subst.c:1511) and we never get warnings (tested on Fedora-38):
% printf "%s\n" ${(#X):-0x8000_0000}
zsh: character not in range
% printf "%s\n" ${(#X):-0x1_0000_0000} | hexdump -C
00000000 00 0a |..|
00000002
% printf "%s\n" ${(#X):-0x1_8000_0000} | hexdump -C
zsh: character not in range
% printf "%s\n" ${(#X):--1} | hexdump -C
00000000 ff 0a |..|
00000002
% printf "%s\n" ${(#X):--0x8000_0001} | hexdump -C
00000000 ff 0a |..|
00000002
diff --git a/Src/subst.c b/Src/subst.c
index 14947ae36..6d9197d44 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3572,7 +3572,7 @@ colonsubscript:
if (errflag)
return NULL;
if (evalchar) {
- int one = noerrs, oef = errflag, haserr = 0;
+ int one = noerrs, haserr = 0;
if (!quoteerr)
noerrs = 1;
@@ -3582,28 +3582,33 @@ colonsubscript:
*/
if (isarr) {
char **aval2, **avptr, **av2ptr;
+ int tmp_errflag = 0; /* errflag==0 at this point */
aval2 = (char **)zhalloc((arrlen(aval)+1)*sizeof(char *));
for (avptr = aval, av2ptr = aval2; *avptr; avptr++, av2ptr++)
{
- /* When noerrs = 1, the only error is out-of-memory */
- if (!(*av2ptr = substevalchar(*avptr))) {
+ /* errflag must be cleared when calling substevalchar().
+ * It will set errflag if conversion fails. */
+ errflag = 0;
+ *av2ptr = substevalchar(*avptr);
+ tmp_errflag |= errflag;
+ if (!*av2ptr) { /* not a valid numerical expression? */
haserr = 1;
break;
}
}
+ errflag = tmp_errflag;
*av2ptr = NULL;
aval = aval2;
} else {
- /* When noerrs = 1, the only error is out-of-memory */
if (!(val = substevalchar(val)))
haserr = 1;
}
noerrs = one;
if (!quoteerr) {
/* Retain user interrupt error status */
- errflag = oef | (errflag & ERRFLAG_INT);
+ errflag &= ERRFLAG_INT;
}
if (haserr || errflag)
return NULL;
next prev parent reply other threads:[~2023-09-07 14:27 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 7:27 Stephane Chazelas
2023-08-30 19:45 ` Bart Schaefer
2023-08-31 17:38 ` Jun. T
2023-09-07 14:26 ` Jun. T [this message]
2023-09-07 16:33 ` Peter Stephenson
2023-09-08 16:30 ` Jun. T
2023-09-11 8:57 ` Peter Stephenson
2023-09-11 12:11 ` Jun. T
2023-09-13 9:59 ` Jun T
2023-09-21 9:26 ` Jun T
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=EBF09792-A011-44F6-A36C-8F704A1A1FF8@kba.biglobe.ne.jp \
--to=takimoto-j@kba.biglobe.ne.jp \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).