mirror of
				git://git.code.sf.net/p/cdesktopenv/code
				synced 2025-03-09 15:50:02 +00:00 
			
		
		
		
	Merge pull request #16 from JohnoKing/fix-optimized-variables
Remove a buggy optimization for variables in subshells Fixes #15
This commit is contained in:
		
						commit
						503a596a3e
					
				
					 3 changed files with 16 additions and 3 deletions
				
			
		
							
								
								
									
										3
									
								
								NEWS
									
										
									
									
									
								
							
							
						
						
									
										3
									
								
								NEWS
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -7,6 +7,9 @@ Any uppercase BUG_* names are modernish shell bug IDs.
 | 
			
		|||
 | 
			
		||||
- The 'source' alias has been converted into a regular built-in command.
 | 
			
		||||
 | 
			
		||||
- Functions that set variables in a virtual subshell will no longer affect
 | 
			
		||||
  variables of the same name outside of the virtual subshell's environment.
 | 
			
		||||
 | 
			
		||||
2020-06-14:
 | 
			
		||||
 | 
			
		||||
- 'read -S' is now able to correctly handle strings with double quotes
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -251,9 +251,6 @@ Namval_t *sh_assignok(register Namval_t *np,int add)
 | 
			
		|||
	/* don't bother with this */
 | 
			
		||||
	if(!sp->shpwd || np==SH_LEVELNOD || np==L_ARGNOD || np==SH_SUBSCRNOD || np==SH_NAMENOD)
 | 
			
		||||
		return(np);
 | 
			
		||||
	/* don't bother to save if in newer scope */
 | 
			
		||||
	if(sp->var!=shp->var_tree && sp->var!=shp->var_base && shp->last_root==shp->var_tree)
 | 
			
		||||
		return(np);
 | 
			
		||||
	if((ap=nv_arrayptr(np)) && (mp=nv_opensub(np)))
 | 
			
		||||
	{
 | 
			
		||||
		shp->last_root = ap->table;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -726,5 +726,18 @@ check_hash_table()
 | 
			
		|||
(hash cat)
 | 
			
		||||
[[ $(hash) == "chmod=$(whence -p chmod)" ]] || err_exit $'changes to a subshell\'s hash table affect the parent shell'
 | 
			
		||||
 | 
			
		||||
# ======
 | 
			
		||||
# Variables set in functions inside of a virtual subshell should not affect the
 | 
			
		||||
# outside environment. This regression test must be run from the disk.
 | 
			
		||||
testvars=$tmp/testvars.sh
 | 
			
		||||
cat >| "$testvars" << 'EOF'
 | 
			
		||||
c=0
 | 
			
		||||
function set_ac { a=1; c=1; }
 | 
			
		||||
function set_abc { ( set_ac ; b=1 ) }
 | 
			
		||||
set_abc
 | 
			
		||||
echo "a=$a b=$b c=$c"
 | 
			
		||||
EOF
 | 
			
		||||
v=$($SHELL $testvars) && [[ "$v" == "a= b= c=0" ]] || err_exit 'variables set in subshells are not confined to the subshell'
 | 
			
		||||
 | 
			
		||||
# ======
 | 
			
		||||
exit $((Errors<125?Errors:125))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue