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

Re: local variable setting problem/bug



> But even worse than that, try the following function:
> 
>     bug()
>     {
> 	local a=()
> 	local b
> 	local c
>     }
> 
> On Nextstep 3.3 running zsh 3.00 or zsh 3.01 (with -f option) I get:
> 	zsh: 24224 segmentation fault  zsh -f
> 
> On Linux 1.3.52 running zsh 2.6-beta13 I get (after a while):
> 	zsh: fatal error: out of memory
> 
> And on Irix 5.2 running zsh 3.00 it also consumes memory and
> won't terminate normally.

That's not surprising since local a=() in fact defined a function local and
a function a= which executed local b.  So the function called local
recursively calls itself and there is not exit from this recursion.  You
probably wanted to use it as

bug() {
	local a
	a=()
	...
}

You cannot initialise local variables with an array at declaration.  You
must use a separate assignment for that.

Zoltan



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