Roman Rakus 57e6a8
			     BASH PATCH REPORT
Roman Rakus 57e6a8
			     =================
Roman Rakus 57e6a8
Roman Rakus 57e6a8
Bash-Release:	4.2
Roman Rakus 57e6a8
Patch-ID:	bash42-025
Roman Rakus 57e6a8
Roman Rakus 57e6a8
Bug-Reported-by:	Bill Gradwohl <bill@ycc.com>
Roman Rakus 57e6a8
Bug-Reference-ID:	<CAFyvKis-UfuOWr5THBRKh=vYHDoKEEgdW8hN1RviTuYQ00Lu5A@mail.gmail.com>
Roman Rakus 57e6a8
Bug-Reference-URL:	http://lists.gnu.org/archive/html/help-bash/2012-03/msg00078.html
Roman Rakus 57e6a8
Roman Rakus 57e6a8
Bug-Description:
Roman Rakus 57e6a8
Roman Rakus 57e6a8
When used in a shell function, `declare -g -a array=(compound assignment)'
Roman Rakus 57e6a8
creates a local variable instead of a global one.
Roman Rakus 57e6a8
Roman Rakus 57e6a8
Patch (apply with `patch -p0'):
Roman Rakus 57e6a8
Roman Rakus 57e6a8
*** ../bash-4.2-patched/command.h	2010-08-02 19:36:51.000000000 -0400
Roman Rakus 57e6a8
--- command.h	2012-04-01 12:38:35.000000000 -0400
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 98,101 ****
Roman Rakus 57e6a8
--- 98,102 ----
Roman Rakus 57e6a8
  #define W_ASSIGNASSOC	0x400000	/* word looks like associative array assignment */
Roman Rakus 57e6a8
  #define W_ARRAYIND	0x800000	/* word is an array index being expanded */
Roman Rakus 57e6a8
+ #define W_ASSNGLOBAL	0x1000000	/* word is a global assignment to declare (declare/typeset -g) */
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
  /* Possible values for subshell_environment */
Roman Rakus 57e6a8
*** ../bash-4.2-patched/execute_cmd.c	2011-11-21 18:03:41.000000000 -0500
Roman Rakus 57e6a8
--- execute_cmd.c	2012-04-01 12:42:03.000000000 -0400
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 3581,3585 ****
Roman Rakus 57e6a8
    WORD_LIST *w;
Roman Rakus 57e6a8
    struct builtin *b;
Roman Rakus 57e6a8
!   int assoc;
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    if (words == 0)
Roman Rakus 57e6a8
--- 3581,3585 ----
Roman Rakus 57e6a8
    WORD_LIST *w;
Roman Rakus 57e6a8
    struct builtin *b;
Roman Rakus 57e6a8
!   int assoc, global;
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    if (words == 0)
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 3587,3591 ****
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    b = 0;
Roman Rakus 57e6a8
!   assoc = 0;
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    for (w = words; w; w = w->next)
Roman Rakus 57e6a8
--- 3587,3591 ----
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    b = 0;
Roman Rakus 57e6a8
!   assoc = global = 0;
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
    for (w = words; w; w = w->next)
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 3604,3607 ****
Roman Rakus 57e6a8
--- 3604,3609 ----
Roman Rakus 57e6a8
  	if (assoc)
Roman Rakus 57e6a8
  	  w->word->flags |= W_ASSIGNASSOC;
Roman Rakus 57e6a8
+ 	if (global)
Roman Rakus 57e6a8
+ 	  w->word->flags |= W_ASSNGLOBAL;
Roman Rakus 57e6a8
  #endif
Roman Rakus 57e6a8
        }
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 3609,3613 ****
Roman Rakus 57e6a8
      /* Note that we saw an associative array option to a builtin that takes
Roman Rakus 57e6a8
         assignment statements.  This is a bit of a kludge. */
Roman Rakus 57e6a8
!     else if (w->word->word[0] == '-' && strchr (w->word->word, 'A'))
Roman Rakus 57e6a8
        {
Roman Rakus 57e6a8
  	if (b == 0)
Roman Rakus 57e6a8
--- 3611,3618 ----
Roman Rakus 57e6a8
      /* Note that we saw an associative array option to a builtin that takes
Roman Rakus 57e6a8
         assignment statements.  This is a bit of a kludge. */
Roman Rakus 57e6a8
!     else if (w->word->word[0] == '-' && (strchr (w->word->word+1, 'A') || strchr (w->word->word+1, 'g')))
Roman Rakus 57e6a8
! #else
Roman Rakus 57e6a8
!     else if (w->word->word[0] == '-' && strchr (w->word->word+1, 'g'))
Roman Rakus 57e6a8
! #endif
Roman Rakus 57e6a8
        {
Roman Rakus 57e6a8
  	if (b == 0)
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 3619,3626 ****
Roman Rakus 57e6a8
  	      words->word->flags |= W_ASSNBLTIN;
Roman Rakus 57e6a8
  	  }
Roman Rakus 57e6a8
! 	if (words->word->flags & W_ASSNBLTIN)
Roman Rakus 57e6a8
  	  assoc = 1;
Roman Rakus 57e6a8
        }
Roman Rakus 57e6a8
- #endif
Roman Rakus 57e6a8
  }
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
--- 3624,3632 ----
Roman Rakus 57e6a8
  	      words->word->flags |= W_ASSNBLTIN;
Roman Rakus 57e6a8
  	  }
Roman Rakus 57e6a8
! 	if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'A'))
Roman Rakus 57e6a8
  	  assoc = 1;
Roman Rakus 57e6a8
+ 	if ((words->word->flags & W_ASSNBLTIN) && strchr (w->word->word+1, 'g'))
Roman Rakus 57e6a8
+ 	  global = 1;
Roman Rakus 57e6a8
        }
Roman Rakus 57e6a8
  }
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
*** ../bash-4.2-patched/subst.c	2012-03-11 17:35:13.000000000 -0400
Roman Rakus 57e6a8
--- subst.c	2012-04-01 12:38:35.000000000 -0400
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 367,370 ****
Roman Rakus 57e6a8
--- 367,375 ----
Roman Rakus 57e6a8
        fprintf (stderr, "W_ASSNBLTIN%s", f ? "|" : "");
Roman Rakus 57e6a8
      }
Roman Rakus 57e6a8
+   if (f & W_ASSNGLOBAL)
Roman Rakus 57e6a8
+     {
Roman Rakus 57e6a8
+       f &= ~W_ASSNGLOBAL;
Roman Rakus 57e6a8
+       fprintf (stderr, "W_ASSNGLOBAL%s", f ? "|" : "");
Roman Rakus 57e6a8
+     }
Roman Rakus 57e6a8
    if (f & W_COMPASSIGN)
Roman Rakus 57e6a8
      {
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 2804,2808 ****
Roman Rakus 57e6a8
    else if (assign_list)
Roman Rakus 57e6a8
      {
Roman Rakus 57e6a8
!       if (word->flags & W_ASSIGNARG)
Roman Rakus 57e6a8
  	aflags |= ASS_MKLOCAL;
Roman Rakus 57e6a8
        if (word->flags & W_ASSIGNASSOC)
Roman Rakus 57e6a8
--- 2809,2813 ----
Roman Rakus 57e6a8
    else if (assign_list)
Roman Rakus 57e6a8
      {
Roman Rakus 57e6a8
!       if ((word->flags & W_ASSIGNARG) && (word->flags & W_ASSNGLOBAL) == 0)
Roman Rakus 57e6a8
  	aflags |= ASS_MKLOCAL;
Roman Rakus 57e6a8
        if (word->flags & W_ASSIGNASSOC)
Roman Rakus 57e6a8
Roman Rakus 57e6a8
*** ../bash-4.2-patched/patchlevel.h	Sat Jun 12 20:14:48 2010
Roman Rakus 57e6a8
--- patchlevel.h	Thu Feb 24 21:41:34 2011
Roman Rakus 57e6a8
***************
Roman Rakus 57e6a8
*** 26,30 ****
Roman Rakus 57e6a8
     looks for to find the patch level (for the sccs version string). */
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
! #define PATCHLEVEL 24
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
  #endif /* _PATCHLEVEL_H_ */
Roman Rakus 57e6a8
--- 26,30 ----
Roman Rakus 57e6a8
     looks for to find the patch level (for the sccs version string). */
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
! #define PATCHLEVEL 25
Roman Rakus 57e6a8
  
Roman Rakus 57e6a8
  #endif /* _PATCHLEVEL_H_ */