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

Re: PATCH: Re: `foo=foo; (( foo ))' => infinite recursion



Bart Schaefer wrote:

> On Mar 14,  9:05am, Sven Wischnowsky wrote:
> } Subject: PATCH: Re: `foo=foo; (( foo ))' => infinite recursion
> }
> } 
> } Bart Schaefer wrote:
> } 
> } > On Mar 13, 10:34am, Sven Wischnowsky wrote:
> } > } Subject: Re: `foo=foo; (( foo ))' => infinite recursion
> } > }
> } > } What really irritated me was that getnumvalue() called matheval().
> } > 
> } > Maybe just a recursion counter with a reasonably large limit?
> } 
> } Ok.
> 
> Something is still too aggressive:
> 
> zagzig% foo='x > 0 ? (--x, y += foo) : 1'
> zagzig% x=3
> zagzig% echo $[foo]
> zsh: math recursion limit exceeded
> 
> `foo' should have been evaluated at most three times, no?
> 
> Maybe there's no real reason to fix this ...

Ugh. Evaluating `.. ? .. : ..' or `.. || ..' or `.. && ..' set noeval
for the unused part but it still called getnparam() and the like.

Bye
 Sven

diff -ru ../z.old/Src/init.c Src/init.c
--- ../z.old/Src/init.c	Tue Mar 14 16:50:21 2000
+++ Src/init.c	Wed Mar 15 10:04:53 2000
@@ -568,6 +568,9 @@
 
     init_eprog();
 
+    zero_mnumber.type = MN_INTEGER;
+    zero_mnumber.u.l = 0;
+
     getkeyptr = NULL;
 
     lineno = 1;
diff -ru ../z.old/Src/math.c Src/math.c
--- ../z.old/Src/math.c	Tue Mar 14 16:50:22 2000
+++ Src/math.c	Wed Mar 15 10:04:07 2000
@@ -37,6 +37,11 @@
 /**/
 int noeval;
  
+/* integer zero */
+
+/**/
+mnumber zero_mnumber;
+
 /* last input base we used */
 
 /**/
@@ -1018,13 +1023,13 @@
 	    push(yyval, NULL);
 	    break;
 	case ID:
-	    push(getnparam(yylval), yylval);
+	    push((noeval ? zero_mnumber : getnparam(yylval)), yylval);
 	    break;
 	case CID:
-	    push(getcvar(yylval), yylval);
+	    push((noeval ? zero_mnumber : getcvar(yylval)), yylval);
 	    break;
 	case FUNC:
-	    push(callmathfunc(yylval), yylval);
+	    push((noeval ? zero_mnumber : callmathfunc(yylval)), yylval);
 	    break;
 	case M_INPAR:
 	    mathparse(TOPPREC);

--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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