bug-bash
[Top][All Lists]
Advanced

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

Re: Executing 'return' inside RETURN trap causes function to recurse inf


From: Chet Ramey
Subject: Re: Executing 'return' inside RETURN trap causes function to recurse infinitely
Date: Sun, 09 Mar 2014 13:50:43 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 3/7/14, 2:38 PM, Eduardo A. Bustamante López wrote:
> WARNING: the codes given below cause the shell to enter an infinite
> loop.
> 
> 
> Both:
> dualbus@debian:~$ bash -Tc 'f(){ :; }; trap return RETURN; f'
> ^C
> 
> and:
> dualbus@debian:~$ bash -c 'f(){ trap return RETURN; }; f'
> ^C
> 
> Cause the function call to recurse infinitely. I would understand if
> this is labeled as a feature, rather than a bug (in the sense that
> the user shouldn't be putting return inside a return trap :), so one
> can safely assume that if they did it, it's because they wanted the
> infinite recursion).

This isn't intended; the a `return' from a return trap should behave like
`exit' in an exit trap and not run the trap recursively.  There is code
in there that's intended to do that; the longjmp that the return builtin
executes defeats those mechanisms.  I will figure out a solution and put
it out as a future patch.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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