---
Hello!

You will not believe it, but now that i was reading over the mail
i sent to busybox@ i saw a comma related bug in _op_apply(), and
that lead me to another test, and that then to another fix even!

 shell/shexp-arith.h | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/shell/shexp-arith.h b/shell/shexp-arith.h
index 96a63bd2b9..2fb867f1c2 100644
--- a/shell/shexp-arith.h
+++ b/shell/shexp-arith.h
@@ -687,13 +687,23 @@ junapre:
 
                   if(delay)
                      ++sasp->sas_ops_top;
-                  a_SHEXP_ARITH_L((" + _arith_eval DELAY TERNARY ?:%s\n",
+                  a_SHEXP_ARITH_L((" + _arith_eval %sTERNARY ?:%s\n",
+                     (delay ? "DELAY " : su_empty),
                      ((op & a_SHEXP_ARITH_OP_FLAG_WHITE_MASK)
                       ? " WHITEOUT" : su_empty)));
                   break;
                }
                /* Is this a right-associative operation? */
                else if(lprec < prec){
+                  /* There is a special case though: if we are about to delay
+                   * a comma sequence, and the LHV is a variable, then we need
+                   * to expand that immediately, in order to correctly get
+                   *    I1=I2=10 I2=3; echo $(( I1, I2 )) */
+                  if(op == a_SHEXP_ARITH_OP_COMMA &&
+                        sasp->sas_nums_top[-1].sav_var != NIL &&
+                        !a_shexp__arith_val_eval(self,
+                           &sasp->sas_nums_top[-1]))
+                     goto jleave;
                   ++sasp->sas_ops_top;
                   a_SHEXP_ARITH_L((" + _arith_eval DELAY PRECEDENCE\n"));
                   break;
@@ -837,8 +847,8 @@ a_shexp__arith_val_eval(struct a_shexp_arith_ctx *self,
 
    /* cp must be a self-contained expression.
     * However, in most cases it solely consists of an integer, shortcut it! */
-   if(su_cs_is_digit(*cp) && (su_idec_cp(&savp->sav_val, cp, 0,
-            a_SHEXP_ARITH_IDEC_MODE, NIL) & su_IDEC_STATE_CONSUMED)){
+   if(su_idec_cp(&savp->sav_val, cp, 0, a_SHEXP_ARITH_IDEC_MODE, NIL
+         ) & su_IDEC_STATE_CONSUMED){
       a_SHEXP_ARITH_L((" + _arith_val_eval NUM DIRECT <%lld>\n",
          savp->sav_val));
    }else{
@@ -956,8 +966,7 @@ a_shexp__arith_op_apply(struct a_shexp_arith_ctx *self){
          goto jquick;
 
       /* Resolve LHV as necessary */
-      if(op != a_SHEXP_ARITH_OP_COMMA && op != a_SHEXP_ARITH_OP_ASSIGN &&
-            nums_top->sav_var != NIL &&
+      if(op != a_SHEXP_ARITH_OP_ASSIGN && nums_top->sav_var != NIL &&
             !a_shexp__arith_val_eval(self, nums_top))
          goto jleave;
 
-- 
2.37.1


--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to