Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: (LC_ALL=C; set -x 128 129; printf "%s\n" ${(#)@} | hexdump -C)



> 2023/09/08 1:33, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx> wrote:
> 
> Looks like these are the only calls to substevalchar(), so perhaps
> the changes could be made internal to that.

I changed paramsubst() just because we can assume errflag=0 at the
start of the block (and would make the things simpler.).

But, anyway, my previous patch was not complete.
Either with or without my previous patch (in any locale):

% echo ${(#X):-@}
zsh: bad math expression: illegal character: @

This is OK. But:

% printf "%s\n" ${(#):-@} | hexdump -C 
00000000  22 0a 22                                          |"."|
00000003

The quote removal is done in remnulargs() ( at subst.c:169).
So it seems that if noerrs is set (without (X) flag) then we should not
quit from prefork() at line 146. This means, I guess, substevalchar()
should not return NULL if noerrs is set. But if we want to continue
even if we have a bad math expression, only thing we can do is just
to return "" instead of NULL. The patch below (hopefuly) does this.
Any comment is welcome.


diff --git a/Src/subst.c b/Src/subst.c
index 14947ae36..d68159227 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -1489,11 +1489,18 @@ subst_parse_str(char **sp, int single, int err)
 static char *
 substevalchar(char *ptr)
 {
-    zlong ires = mathevali(ptr);
+    zlong ires;
     int len = 0;
+    int saved_errflag = errflag;
 
-    if (errflag)
-	return NULL;
+    errflag = 0;
+    ires = mathevali(ptr);
+
+    if (errflag) {  /* not a valid numerical expression */
+	errflag |= saved_errflag;
+	return noerrs ? dupstring(""): NULL;
+    }
+    errflag |= saved_errflag;
 #ifdef MULTIBYTE_SUPPORT
     if (isset(MULTIBYTE) && ires > 127) {
 	/* '\\' + 'U' + 8 bytes of character + '\0' */







Messages sorted by: Reverse Date, Date, Thread, Author