mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 23:24:39 +00:00
Fix the code for ignoring infinite recursion
darcs-hash:20061102134537-ac50b-2dddd06dd77c362caf44c9160acc29b76278b230.gz
This commit is contained in:
parent
7fb44d4d5f
commit
6e24b26e2c
2 changed files with 33 additions and 8 deletions
36
parser.c
36
parser.c
|
@ -1669,6 +1669,7 @@ static void parse_job_argument_list( process_t *p,
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
static void print_block_stack( block_t *b )
|
||||
{
|
||||
|
@ -1931,16 +1932,31 @@ static int parse_job( process_t *p,
|
|||
int nxt_forbidden=0;
|
||||
wchar_t *forbid;
|
||||
|
||||
if( current_block->type == FUNCTION_CALL )
|
||||
int is_function_call=0;
|
||||
|
||||
/*
|
||||
This is a bit fragile. It is a test to see if we are
|
||||
inside of function call, but not inside a block in that
|
||||
function call. If, in the future, the rules for what
|
||||
block scopes are pushed on function invocation changes,
|
||||
then this check will break.
|
||||
*/
|
||||
if( ( current_block->type == TOP ) &&
|
||||
( current_block->outer ) &&
|
||||
( current_block->outer->type == FUNCTION_CALL ) )
|
||||
is_function_call = 1;
|
||||
|
||||
/*
|
||||
If we are directly in a function, and this is the first
|
||||
command of the block, then the function we are executing
|
||||
may not be called, since that would mean an infinite
|
||||
recursion.
|
||||
*/
|
||||
if( is_function_call && !current_block->had_command )
|
||||
{
|
||||
forbid = (wchar_t *)(al_get_count( forbidden_function)?al_peek( forbidden_function ):0);
|
||||
nxt_forbidden = forbid && (wcscmp( forbid, nxt) == 0 );
|
||||
}
|
||||
|
||||
/*
|
||||
Make feeble attempt to avoid infinite recursion. Will at
|
||||
least catch some accidental infinite recursion calls.
|
||||
*/
|
||||
|
||||
if( !nxt_forbidden && function_exists( nxt ) )
|
||||
{
|
||||
|
@ -2198,6 +2214,14 @@ static int parse_job( process_t *p,
|
|||
}
|
||||
}
|
||||
|
||||
if( !error_code )
|
||||
{
|
||||
if( !is_new_block )
|
||||
{
|
||||
current_block->had_command = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if( error_code )
|
||||
{
|
||||
/*
|
||||
|
|
5
parser.h
5
parser.h
|
@ -47,7 +47,8 @@ typedef struct block
|
|||
int type; /**< Type of block. Can be one of WHILE, FOR, IF and FUNCTION */
|
||||
int skip; /**< Whether execution of the commands in this block should be skipped */
|
||||
int tok_pos; /**< The start index of the block */
|
||||
|
||||
int had_command; /**< Set to non-zero once a command has been executed in this block */
|
||||
|
||||
/**
|
||||
Status for the current loop block. Can be any of the values from the loop_status enum.
|
||||
*/
|
||||
|
@ -210,7 +211,7 @@ int eval_args( const wchar_t *line,
|
|||
array_list_t *output );
|
||||
|
||||
/**
|
||||
Sets the current error
|
||||
Sets the current evaluation error. This function should only be used by libraries that are called by
|
||||
|
||||
\param ec The new error code
|
||||
\param p The character offset at which the error occured
|
||||
|
|
Loading…
Reference in a new issue