From 85d069c106381a4b4497796e27a9b42c00805c73 Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 27 Jan 2007 03:14:13 +1000 Subject: [PATCH] Fix crash in tab completion code when completing an imcomplete backsalsh escape darcs-hash:20070126171413-ac50b-a9338dc73863381f2b22e09fb8b5e711f64b8f29.gz --- common.c | 27 ++++++++++++++++++++------- complete.c | 15 +++++++++------ parse_util.c | 3 --- reader.c | 5 +++++ tokenizer.c | 35 ++++++++++++----------------------- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/common.c b/common.c index 16e8b09b9..3d5a97ca7 100644 --- a/common.c +++ b/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 '\\': diff --git a/complete.c b/complete.c index b1c35acaf..f649d65f1 100644 --- a/complete.c +++ b/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 ); diff --git a/parse_util.c b/parse_util.c index 9d792b8f1..fba126fb8 100644 --- a/parse_util.c +++ b/parse_util.c @@ -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; } diff --git a/reader.c b/reader.c index 9a1129d88..4ad6e2ed7 100644 --- a/reader.c +++ b/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); diff --git a/tokenizer.c b/tokenizer.c index 4f48e46e4..1fe002db2 100644 --- a/tokenizer.c +++ b/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; }