bug-bash
[Top][All Lists]
Advanced

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

Re: a recursion bug


From: Dan Douglas
Subject: Re: a recursion bug
Date: Thu, 4 Oct 2012 10:47:45 -0500

It's possible to grow the parameter expansion stack forever too.

 $ (x=x[\${!x}]<${!x})
Segmentation fault

One would think there would be no need to keep a stack if there are no
more expansions to the right of the current expansion.

On Wed, Oct 3, 2012 at 3:39 PM, Chet Ramey <chet.ramey@case.edu> wrote:
> On 10/3/12 3:40 PM, Greg Wooledge wrote:
>> On Wed, Oct 03, 2012 at 01:23:58PM -0600, Bob Proulx wrote:
>>> But in any case, is there
>>> anything in there that is about bash?  If so the we need an exact test
>>> case.
>>
>> You could start with this one:
>>
>> 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.
>
> There's not actually anything you can do about that except use ulimit to
> get as much stack space as you can.

Well, poor-mans TCO

f()
    if [ "$1" -ge 0 ]; then
        printf "$1 "
        exec dash -c "${2}f "'$(($1-1)) "$2"' -- "$@"
    fi

( f 1000000 "$(typeset -f f)"$'\n' )

Joking of course :o)

FUNCNEST is usually good enough for me. No other shell I'm aware of
even has that.
--
Dan Douglas



reply via email to

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