diff options
author | 2012-02-26 13:46:21 -0800 | |
---|---|---|
committer | 2012-02-26 13:46:21 -0800 | |
commit | ad7c5886bc62d2d36d458b9769a6294bffb030da (patch) | |
tree | ee712fb32b0937438bc7e0ad6078443ccaf71133 | |
parent | b30090f9461f246053b846173c81682018901c7e (diff) |
Fix a crash in complete -C
-rw-r--r-- | builtin_complete.cpp | 15 | ||||
-rw-r--r-- | complete.cpp | 4 |
2 files changed, 10 insertions, 9 deletions
diff --git a/builtin_complete.cpp b/builtin_complete.cpp index 3b9657ce..658ff63b 100644 --- a/builtin_complete.cpp +++ b/builtin_complete.cpp @@ -296,7 +296,8 @@ static int builtin_complete( parser_t &parser, wchar_t **argv ) wcstring_list_t gnu_opt, old_opt; const wchar_t *comp=L"", *desc=L"", *condition=L""; - const wchar_t *do_complete = 0; + bool do_complete = false; + wcstring do_complete_param; wcstring_list_t cmd; wcstring_list_t path; @@ -477,7 +478,8 @@ static int builtin_complete( parser_t &parser, wchar_t **argv ) break; case 'C': - do_complete = woptarg?woptarg:reader_get_buffer(); + do_complete = true; + do_complete_param = woptarg ? woptarg : reader_get_buffer(); break; case 'h': @@ -535,19 +537,18 @@ static int builtin_complete( parser_t &parser, wchar_t **argv ) { std::vector<completion_t> comp; - const wchar_t *prev_temporary_buffer = temporary_buffer; - const wchar_t *token; - parse_util_token_extent( do_complete, wcslen( do_complete ), &token, 0, 0, 0 ); + parse_util_token_extent( do_complete_param.c_str(), do_complete_param.size(), &token, 0, 0, 0 ); - temporary_buffer = do_complete; + const wchar_t *prev_temporary_buffer = temporary_buffer; + temporary_buffer = do_complete_param.c_str(); if( recursion_level < 1 ) { recursion_level++; - complete( do_complete, comp, COMPLETE_DEFAULT ); + complete( do_complete_param, comp, COMPLETE_DEFAULT ); for( size_t i=0; i< comp.size() ; i++ ) { diff --git a/complete.cpp b/complete.cpp index b6c7499a..b203b4a8 100644 --- a/complete.cpp +++ b/complete.cpp @@ -1507,8 +1507,8 @@ bool completer_t::complete_variable(const wcstring &str, int start_offset) */ bool completer_t::try_complete_variable( const wcstring &str ) { - size_t i, len = str.size(); - for( i=len-1; i>=0; i-- ) + size_t i = str.size(); + while (i--) { wchar_t c = str.at(i); if( c == L'$' ) |