mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-01-19 02:32:46 +08:00
Fix crash bug when pasting long text
darcs-hash:20051027152148-ac50b-b47b96bc8acae760ce53a2e42d23dc2d07bf2302.gz
This commit is contained in:
parent
43213ee458
commit
b78fba810c
22
expand.c
22
expand.c
|
@ -1121,9 +1121,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
len1 = (paran_begin-in);
|
len1 = (paran_begin-in);
|
||||||
len2 = wcslen(paran_end)-1;
|
len2 = wcslen(paran_end)-1;
|
||||||
|
@ -1147,10 +1145,10 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||||
free( subcmd );
|
free( subcmd );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
al_init( &tail_expand );
|
al_init( &tail_expand );
|
||||||
expand_subshell( wcsdup(paran_end+1), &tail_expand );
|
expand_subshell( wcsdup(paran_end+1), &tail_expand );
|
||||||
|
|
||||||
for( i=0; i<al_get_count( &sub_res ); i++ )
|
for( i=0; i<al_get_count( &sub_res ); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *sub_item, *sub_item2;
|
wchar_t *sub_item, *sub_item2;
|
||||||
|
@ -1158,20 +1156,20 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||||
sub_item2 = expand_escape( sub_item, 1 );
|
sub_item2 = expand_escape( sub_item, 1 );
|
||||||
free(sub_item);
|
free(sub_item);
|
||||||
int item_len = wcslen( sub_item2 );
|
int item_len = wcslen( sub_item2 );
|
||||||
|
|
||||||
for( j=0; j<al_get_count( &tail_expand ); j++ )
|
for( j=0; j<al_get_count( &tail_expand ); j++ )
|
||||||
{
|
{
|
||||||
string_buffer_t whole_item;
|
string_buffer_t whole_item;
|
||||||
wchar_t *tail_item = (wchar_t *)al_get( &tail_expand, j );
|
wchar_t *tail_item = (wchar_t *)al_get( &tail_expand, j );
|
||||||
|
|
||||||
sb_init( &whole_item );
|
sb_init( &whole_item );
|
||||||
|
|
||||||
sb_append_substring( &whole_item, in, len1 );
|
sb_append_substring( &whole_item, in, len1 );
|
||||||
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
||||||
sb_append_substring( &whole_item, sub_item2, item_len );
|
sb_append_substring( &whole_item, sub_item2, item_len );
|
||||||
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
|
||||||
sb_append( &whole_item, tail_item );
|
sb_append( &whole_item, tail_item );
|
||||||
|
|
||||||
al_push( out, whole_item.buff );
|
al_push( out, whole_item.buff );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1183,7 +1181,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
|
||||||
|
|
||||||
al_foreach( &tail_expand, (void (*)(const void *))&free );
|
al_foreach( &tail_expand, (void (*)(const void *))&free );
|
||||||
al_destroy( &tail_expand );
|
al_destroy( &tail_expand );
|
||||||
|
|
||||||
free( subcmd );
|
free( subcmd );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1246,7 +1244,7 @@ static int tilde_expand( wchar_t **ptr )
|
||||||
old_in = name_end;
|
old_in = name_end;
|
||||||
|
|
||||||
char *name_str = wcs2str( name );
|
char *name_str = wcs2str( name );
|
||||||
|
|
||||||
struct passwd *userinfo =
|
struct passwd *userinfo =
|
||||||
getpwnam( name_str );
|
getpwnam( name_str );
|
||||||
|
|
||||||
|
@ -1397,7 +1395,7 @@ int expand_string( wchar_t *str,
|
||||||
for( i=0; i<al_get_count( in ); i++ )
|
for( i=0; i<al_get_count( in ); i++ )
|
||||||
{
|
{
|
||||||
wchar_t *next;
|
wchar_t *next;
|
||||||
|
|
||||||
next = expand_unescape( (wchar_t *)al_get( in, i ),
|
next = expand_unescape( (wchar_t *)al_get( in, i ),
|
||||||
1);
|
1);
|
||||||
|
|
||||||
|
|
5
reader.c
5
reader.c
|
@ -1007,12 +1007,13 @@ static int insert_str(wchar_t *str)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int old_len = data->buff_len;
|
||||||
|
|
||||||
data->buff_len += len;
|
data->buff_len += len;
|
||||||
check_size();
|
check_size();
|
||||||
|
|
||||||
/* Insert space for extra character at the right position */
|
/* Insert space for extra characters at the right position */
|
||||||
if( data->buff_pos < data->buff_len )
|
if( data->buff_pos < old_len )
|
||||||
{
|
{
|
||||||
memmove( &data->buff[data->buff_pos+len],
|
memmove( &data->buff[data->buff_pos+len],
|
||||||
&data->buff[data->buff_pos],
|
&data->buff[data->buff_pos],
|
||||||
|
|
30
wutil.c
30
wutil.c
|
@ -22,22 +22,37 @@
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wutil.h"
|
#include "wutil.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
Buffer for converting wide arguments to narrow arguments, used by
|
||||||
|
the \c wutil_wcs2str() function.
|
||||||
|
*/
|
||||||
static char *tmp=0;
|
static char *tmp=0;
|
||||||
|
/**
|
||||||
|
Length of the \c tmp buffer.
|
||||||
|
*/
|
||||||
static size_t tmp_len=0;
|
static size_t tmp_len=0;
|
||||||
|
|
||||||
int c = 0;
|
/**
|
||||||
|
Counts the number of calls to the wutil wrapper functions
|
||||||
|
*/
|
||||||
|
static int wutil_calls = 0;
|
||||||
|
|
||||||
void wutil_destroy()
|
void wutil_destroy()
|
||||||
{
|
{
|
||||||
free( tmp );
|
free( tmp );
|
||||||
tmp=0;
|
tmp=0;
|
||||||
tmp_len=0;
|
tmp_len=0;
|
||||||
debug( 3, L"wutil functions called %d times", c );
|
debug( 3, L"wutil functions called %d times", wutil_calls );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert the specified wide aharacter string to a narrow character
|
||||||
|
string. This function uses an internal temporary buffer for storing
|
||||||
|
the result so subsequent results will overwrite previous results.
|
||||||
|
*/
|
||||||
static char *wutil_wcs2str( const wchar_t *in )
|
static char *wutil_wcs2str( const wchar_t *in )
|
||||||
{
|
{
|
||||||
c++;
|
wutil_calls++;
|
||||||
|
|
||||||
size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
|
size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
|
||||||
if( tmp_len < new_sz )
|
if( tmp_len < new_sz )
|
||||||
|
@ -109,14 +124,17 @@ int wopen(const wchar_t *pathname, int flags, ...)
|
||||||
|
|
||||||
if( tmp )
|
if( tmp )
|
||||||
{
|
{
|
||||||
va_start( argp, flags );
|
|
||||||
|
|
||||||
if( ! (flags & O_CREAT) )
|
if( ! (flags & O_CREAT) )
|
||||||
|
{
|
||||||
res = open(tmp, flags);
|
res = open(tmp, flags);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
va_start( argp, flags );
|
||||||
res = open(tmp, flags, va_arg(argp, int) );
|
res = open(tmp, flags, va_arg(argp, int) );
|
||||||
|
va_end( argp );
|
||||||
va_end( argp );
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user