bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: a recursion bug


From: Yuxiang Cao
Subject: RE: a recursion bug
Date: Wed, 3 Oct 2012 13:09:13 +0000

Hi,
Actually, I just change to Solaris system and running your code which still not 
work.
Regards,
Yuxiang Cao  
________________________________________
From: Yuxiang Cao
Sent: Wednesday, October 03, 2012 11:00 PM
To: Greg Wooledge
Subject: RE: a recursion bug

Hi, this is a interesting problem.  Because My bash version is 4.1.5, so I 
simply run the similar thing as your code which give me this
address@hidden:~/research/realfault$ bash -c 'FUNCNEST=100; a() { echo "$1"; a 
$(($1+1)); }; a 1' 2>&1 | tail
17692
17693
17694
17695
17696
17697
17698
17699
17700
17701
I think it is not work on Ubuntu 10.4, and that is my OS.
Here is my code
#!/bin/bash
FUNCNEST=100
recursion()
{
        if [ $1 -ne 15000 ] ;then
                echo $1
                let i=$1+1
                recursion $i
        fi
        exit
}
recursion 1
whatever i set FUNCNEST value in my script or export FUNCNEST=100. It is still 
not work. That is weird.
________________________________________
From: Greg Wooledge address@hidden
Sent: Wednesday, October 03, 2012 10:40 PM
To: Yuxiang Cao
Cc: address@hidden
Subject: Re: a recursion bug

On Wed, Oct 03, 2012 at 05:07:16AM +0000, Yuxiang Cao wrote:
> Hi,
> After second thought, I carefully read the bash manual page and find this
> information. Functions may be recursive. The FUNCNEST variable may be used to
> limit the depth of the function call stack and restrict the number of
> function invocations. By default, no limit is placed on the number of
> recursive calls. So in my example, what I think I can do is to limit the
> times of recursive calls. So I simply export FUNCNEST variable as " export
> FUNCNEST=500", however, it doesn't work. That could be a bug for bash, right?

It would help if you show what you're doing and what the result is.
It seems to work correctly here:

imadev:~$ bash-4.2.28 -c 'FUNCNEST=100; a() { echo "$1"; a $(($1+1)); }; a 1' 
2>&1 | tail
92
93
94
95
96
97
98
99
100
bash-4.2.28: a: maximum function nesting level exceeded (100)

Without the FUNCNEST, it runs for several seconds, and then:

imadev:~$ bash-4.2.28 -c 'a() { echo "$1"; a $(($1+1)); }; a 1' 2>&1 | tail
Pid 4466 received a SIGSEGV for stack growth failure.
Possible causes: insufficient memory or swap space,
or stack size exceeded maxssiz.
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
imadev:~$ ls -l core
-rw-------   1 wooledg    pgmr       19908052 Oct  3 08:38 core
imadev:~$ file core
core:           core file from 'bash-4.2.28' - received SIGSEGV

(Happy, Linda?)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]