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

The -~ bug



The problem is that '-' is still tokenized as Dash on entry to filesubstr()
in subst.c.

This is going to break zstrtol() as well, for e.g. ~-3 counting backwards
in the stack, which is done very early before the rest of the filename has
been examined.

But we don't want to untokenize the entire file name; tokens like Brack
and Equals are still important.

Is it safe to do the following, which changes the string passed in via
*namptr?  Or is it necessary to dupstring()?

diff --git a/Src/subst.c b/Src/subst.c
index 06d2c9e..64b4400 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -650,6 +650,8 @@ filesubstr(char **namptr, int assign)
 	char *ptr, *tmp, *res, *ptr2;
 	int val;
 
+	if (str[1] == Dash)
+	    str[1] = '-';
 	val = zstrtol(str + 1, &ptr, 10);
 	if (isend(str[1])) {   /* ~ */
 	    *namptr = dyncat(home ? home : "", str + 1);



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