mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 21:18:53 +00:00
Fisx crash buh when completing string ending in backslash
darcs-hash:20051225220044-ac50b-b880ffe649d04ed1e5ec6786d0b59eed8068d182.gz
This commit is contained in:
parent
b6630b5087
commit
b37eeb92ef
6 changed files with 49 additions and 22 deletions
1
common.c
1
common.c
|
@ -932,7 +932,6 @@ wchar_t *escape( const wchar_t *in,
|
|||
case L'^':
|
||||
case L'<':
|
||||
case L'>':
|
||||
case L'@':
|
||||
case L'(':
|
||||
case L')':
|
||||
case L'[':
|
||||
|
|
|
@ -2017,7 +2017,7 @@ void complete( const wchar_t *cmd,
|
|||
|
||||
tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
|
||||
|
||||
while( !end_loop )
|
||||
while( tok_has_next( &tok) && !end_loop )
|
||||
{
|
||||
switch( tok_last_type( &tok ) )
|
||||
{
|
||||
|
@ -2063,7 +2063,8 @@ void complete( const wchar_t *cmd,
|
|||
reader_current_token_extent( &begin, &end, &prev_begin, &prev_end );
|
||||
|
||||
current_token = wcsndup( begin, reader_get_cursor_pos()-(begin-reader_get_buffer()) );
|
||||
prev_token = wcsndup( prev_begin, prev_end - prev_begin );
|
||||
|
||||
prev_token = prev_begin ? wcsndup( prev_begin, prev_end - prev_begin ): wcsdup(L"");
|
||||
|
||||
// fwprintf( stderr, L"on_command: %d, %ls %ls\n", on_command, current_compmand, current_token );
|
||||
|
||||
|
|
7
expand.c
7
expand.c
|
@ -20,6 +20,8 @@ parameter expansion.
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef SunOS
|
||||
#include <procfs.h>
|
||||
#endif
|
||||
|
@ -1174,6 +1176,11 @@ int expand_locate_subshell( wchar_t *in,
|
|||
*begin = paran_begin;
|
||||
*end = paran_count?in+wcslen(in):paran_end;
|
||||
|
||||
/* assert( *begin >= in );
|
||||
assert( *begin < (in+wcslen(in) ) );
|
||||
assert( *end >= *begin );
|
||||
assert( *end < (in+wcslen(in) ) );
|
||||
*/
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
|
32
reader.c
32
reader.c
|
@ -52,6 +52,8 @@ commence.
|
|||
#include <time.h>
|
||||
#include <wchar.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "wutil.h"
|
||||
#include "highlight.h"
|
||||
|
@ -1829,8 +1831,6 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
|
||||
reader_current_subshell_extent( &begin, &end );
|
||||
|
||||
// fwprintf( stderr, L"Lalala: %d %d %d\n", begin-data->buff, end-data->buff, pos );
|
||||
|
||||
if( !end || !begin )
|
||||
return;
|
||||
|
||||
|
@ -1841,6 +1841,11 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
pa = data->buff + pos;
|
||||
pb = pa;
|
||||
|
||||
assert( begin >= data->buff );
|
||||
assert( begin <= (data->buff+wcslen(data->buff) ) );
|
||||
assert( end >= begin );
|
||||
assert( end <= (data->buff+wcslen(data->buff) ) );
|
||||
|
||||
buffcpy = wcsndup( begin, end-begin );
|
||||
|
||||
if( !buffcpy )
|
||||
|
@ -1855,15 +1860,27 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
int tok_begin = tok_get_pos( &tok );
|
||||
int tok_end=tok_begin;
|
||||
|
||||
/*
|
||||
Calculate end of token
|
||||
*/
|
||||
if( tok_last_type( &tok ) == TOK_STRING )
|
||||
tok_end +=wcslen(tok_last(&tok));
|
||||
|
||||
|
||||
/*
|
||||
Cursor was before beginning of this token, means that the
|
||||
cursor is between two tokens, so we set it to a zero element
|
||||
string and break
|
||||
*/
|
||||
if( tok_begin > pos )
|
||||
{
|
||||
a = b = data->buff + pos;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
If cursor is inside the token, this is the token we are
|
||||
looking for. If so, set a and b and break
|
||||
*/
|
||||
if( tok_end >= pos )
|
||||
{
|
||||
a = begin + tok_get_pos( &tok );
|
||||
|
@ -1874,6 +1891,9 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
Remember previous string token
|
||||
*/
|
||||
if( tok_last_type( &tok ) == TOK_STRING )
|
||||
{
|
||||
pa = begin + tok_get_pos( &tok );
|
||||
|
@ -1881,7 +1901,6 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
}
|
||||
}
|
||||
|
||||
// fwprintf( stderr, L"Res: %d %d\n", *a-data->buff, *b-data->buff );
|
||||
free( buffcpy);
|
||||
|
||||
tok_destroy( &tok );
|
||||
|
@ -1895,7 +1914,10 @@ void reader_current_token_extent( wchar_t **tok_begin,
|
|||
if( prev_end )
|
||||
*prev_end = pb;
|
||||
|
||||
// fwprintf( stderr, L"w00t\n" );
|
||||
assert( pa >= data->buff );
|
||||
assert( pa <= (data->buff+wcslen(data->buff) ) );
|
||||
assert( pb >= pa );
|
||||
assert( pb <= (data->buff+wcslen(data->buff) ) );
|
||||
|
||||
}
|
||||
|
||||
|
|
19
tokenizer.c
19
tokenizer.c
|
@ -119,12 +119,9 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
|||
|
||||
memset( tok, 0, sizeof( tokenizer) );
|
||||
|
||||
tok ->last = 0;
|
||||
tok ->last_len = 0;
|
||||
tok->accept_unfinished = flags & TOK_ACCEPT_UNFINISHED;
|
||||
tok->show_comments = flags & TOK_SHOW_COMMENTS;
|
||||
tok->has_next=1;
|
||||
|
||||
tok->has_next=1;
|
||||
|
||||
/*
|
||||
Before we copy the buffer we need to check that it is not
|
||||
|
@ -139,12 +136,6 @@ 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->orig_buff )
|
||||
{
|
||||
die_mem();
|
||||
|
||||
}
|
||||
|
||||
if( tok->accept_unfinished )
|
||||
{
|
||||
|
@ -154,7 +145,11 @@ void tok_init( tokenizer *tok, const wchar_t *b, int flags )
|
|||
if( tok->orig_buff[l-1] == L'\\' )
|
||||
{
|
||||
tok->free_orig = 1;
|
||||
tok->orig_buff = wcsdup( tok->orig_buff );
|
||||
tok->orig_buff = tok->buff = wcsdup( tok->orig_buff );
|
||||
if( !tok->orig_buff )
|
||||
{
|
||||
die_mem();
|
||||
}
|
||||
tok->orig_buff[l-1] = L'\0';
|
||||
}
|
||||
}
|
||||
|
@ -624,7 +619,7 @@ wchar_t *tok_first( const wchar_t *str )
|
|||
|
||||
int tok_get_pos( tokenizer *tok )
|
||||
{
|
||||
return tok->last_pos;
|
||||
return tok->last_pos + (tok->free_orig?1:0);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -317,8 +317,11 @@ static int test_flags( wchar_t *filename,
|
|||
return 1;
|
||||
|
||||
struct stat buf;
|
||||
wstat( filename, &buf );
|
||||
|
||||
if( wstat( filename, &buf ) == -1 )
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( S_IFDIR & buf.st_mode )
|
||||
return 1;
|
||||
|
||||
|
|
Loading…
Reference in a new issue