mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-13 05:28:49 +00:00
Fix crash in tab completion code when completing an imcomplete backsalsh escape
darcs-hash:20070126171413-ac50b-a9338dc73863381f2b22e09fb8b5e711f64b8f29.gz
This commit is contained in:
parent
cfecb58bb6
commit
85d069c106
5 changed files with 46 additions and 39 deletions
27
common.c
27
common.c
|
@ -861,10 +861,13 @@ wchar_t *unescape( const wchar_t * orig, int flags )
|
|||
*/
|
||||
case L'\0':
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Numeric escape sequences. No prefix means
|
||||
octal escape, otherwise hexadecimal.
|
||||
|
@ -1225,8 +1228,13 @@ wchar_t *unescape( const wchar_t * orig, int flags )
|
|||
|
||||
case 0:
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
out_pos--;
|
||||
}
|
||||
|
||||
default:
|
||||
|
@ -1276,8 +1284,13 @@ wchar_t *unescape( const wchar_t * orig, int flags )
|
|||
{
|
||||
case L'\0':
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
if( !allow_incomplete )
|
||||
{
|
||||
free(in);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
out_pos--;
|
||||
}
|
||||
|
||||
case '\\':
|
||||
|
|
15
complete.c
15
complete.c
|
@ -2288,12 +2288,15 @@ void complete( const wchar_t *cmd,
|
|||
wchar_t *prev_token_unescape = unescape( prev_token, 0 );
|
||||
wchar_t *current_token_unescape = unescape( current_token, UNESCAPE_INCOMPLETE );
|
||||
|
||||
do_file = complete_param( current_command_unescape,
|
||||
prev_token_unescape,
|
||||
current_token_unescape,
|
||||
!had_ddash,
|
||||
comp );
|
||||
|
||||
if( current_token_unescape && prev_token_unescape && current_token_unescape )
|
||||
{
|
||||
do_file = complete_param( current_command_unescape,
|
||||
prev_token_unescape,
|
||||
current_token_unescape,
|
||||
!had_ddash,
|
||||
comp );
|
||||
}
|
||||
|
||||
free( current_command_unescape );
|
||||
free( prev_token_unescape );
|
||||
free( current_token_unescape );
|
||||
|
|
|
@ -492,9 +492,6 @@ void parse_util_token_extent( const wchar_t *buff,
|
|||
{
|
||||
a = begin + tok_get_pos( &tok );
|
||||
b = a + wcslen(tok_last(&tok));
|
||||
|
||||
// fwprintf( stderr, L"Whee %ls\n", *a );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
5
reader.c
5
reader.c
|
@ -2224,6 +2224,11 @@ wchar_t *reader_readline()
|
|||
|
||||
cursor_steps = token_end - data->buff- data->buff_pos;
|
||||
data->buff_pos += cursor_steps;
|
||||
if( is_backslashed( data->buff, data->buff_pos ) )
|
||||
{
|
||||
remove_backward();
|
||||
}
|
||||
|
||||
repaint();
|
||||
|
||||
len = data->buff_pos - (begin-data->buff);
|
||||
|
|
35
tokenizer.c
35
tokenizer.c
|
@ -137,27 +137,7 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
|||
|
||||
tok->has_next = (*b != L'\0');
|
||||
tok->orig_buff = tok->buff = (wchar_t *)(b);
|
||||
|
||||
if( tok->accept_unfinished )
|
||||
{
|
||||
int l = wcslen( tok->orig_buff );
|
||||
if( l != 0 )
|
||||
{
|
||||
if( tok->orig_buff[l-1] == L'\\' )
|
||||
{
|
||||
tok->free_orig = 1;
|
||||
tok->orig_buff = tok->buff = wcsdup( tok->orig_buff );
|
||||
if( !tok->orig_buff )
|
||||
{
|
||||
DIE_MEM();
|
||||
}
|
||||
tok->orig_buff[l-1] = L'\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tok_next( tok );
|
||||
|
||||
}
|
||||
|
||||
void tok_destroy( tokenizer *tok )
|
||||
|
@ -242,8 +222,17 @@ static void read_string( tokenizer *tok )
|
|||
tok->buff++;
|
||||
if( *tok->buff == L'\0' )
|
||||
{
|
||||
tok_error( tok, TOK_UNTERMINATED_ESCAPE, QUOTE_ERROR );
|
||||
return;
|
||||
if( (!tok->accept_unfinished) )
|
||||
{
|
||||
tok_error( tok, TOK_UNTERMINATED_ESCAPE, QUOTE_ERROR );
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
do_loop = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if( *tok->buff == L'\n' && mode == 0)
|
||||
{
|
||||
|
@ -674,7 +663,7 @@ int tok_get_pos( tokenizer *tok )
|
|||
{
|
||||
CHECK( tok, 0 );
|
||||
|
||||
return tok->last_pos + (tok->free_orig?1:0);
|
||||
return tok->last_pos;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue