mac80211: add pending ath9k/ath10k patches
[openwrt.git] / package / utils / busybox / patches / 290-ash-fix-a-regression-in-handling-local-variables.patch
1 From: Felix Fietkau <nbd@openwrt.org>
2 Date: Fri, 17 Apr 2015 01:54:51 +0200
3 Subject: [PATCH] ash: fix a regression in handling local variables
4
5 commit 109ee5d33694a03cda3424b4846584250832ba8e
6 "ash: make "locak VAR" unset VAR (bash does that)"
7
8 This commit introduced a regression where calling local on an already
9 local variable unsets it. This does not match bash behavior.
10
11 Update test case to check for this behavior
12
13 Signed-off-by: Felix Fietkau <nbd@openwrt.org>
14 ---
15
16 --- a/shell/ash.c
17 +++ b/shell/ash.c
18 @@ -8961,6 +8961,21 @@ parse_command_args(char **argv, const ch
19  }
20  #endif
21  
22 +static bool
23 +findlocal(struct var *vp)
24 +{
25 +       struct localvar *lvp = localvars;
26 +
27 +       while (lvp) {
28 +               if (lvp->vp == vp)
29 +                       return true;
30 +
31 +               lvp = lvp->next;
32 +       }
33 +
34 +       return false;
35 +}
36 +
37  /*
38   * Make a variable a local variable.  When a variable is made local, it's
39   * value and flags are saved in a localvar structure.  The saved values
40 @@ -9000,7 +9015,7 @@ mklocal(char *name)
41                         vp->flags |= VSTRFIXED|VTEXTFIXED;
42                         if (eq)
43                                 setvareq(name, 0);
44 -                       else
45 +                       else if (!findlocal(vp))
46                                 /* "local VAR" unsets VAR: */
47                                 setvar(name, NULL, 0);
48                 }
49 --- a/shell/ash_test/ash-misc/local1.right
50 +++ b/shell/ash_test/ash-misc/local1.right
51 @@ -1,4 +1,5 @@
52  A1:'A'
53  A2:''
54 -A3:''
55 -A4:'A'
56 +A3:'B'
57 +A4:''
58 +A5:'A'
59 --- a/shell/ash_test/ash-misc/local1.tests
60 +++ b/shell/ash_test/ash-misc/local1.tests
61 @@ -3,9 +3,12 @@ f() {
62         local a
63         # the above line unsets $a
64         echo "A2:'$a'"
65 -       unset a
66 +       a=B
67 +       local a
68         echo "A3:'$a'"
69 +       unset a
70 +       echo "A4:'$a'"
71  }
72  echo "A1:'$a'"
73  f
74 -echo "A4:'$a'"
75 +echo "A5:'$a'"