Fix crash bug when pasting long text

darcs-hash:20051027152148-ac50b-b47b96bc8acae760ce53a2e42d23dc2d07bf2302.gz
This commit is contained in:
axel 2005-10-28 01:21:48 +10:00
parent 43213ee458
commit b78fba810c
3 changed files with 37 additions and 20 deletions

View file

@ -1121,9 +1121,7 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
break;
}
}
len1 = (paran_begin-in);
len2 = wcslen(paran_end)-1;
@ -1147,10 +1145,10 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
free( subcmd );
return 0;
}
al_init( &tail_expand );
expand_subshell( wcsdup(paran_end+1), &tail_expand );
for( i=0; i<al_get_count( &sub_res ); i++ )
{
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 );
free(sub_item);
int item_len = wcslen( sub_item2 );
for( j=0; j<al_get_count( &tail_expand ); j++ )
{
string_buffer_t whole_item;
wchar_t *tail_item = (wchar_t *)al_get( &tail_expand, j );
sb_init( &whole_item );
sb_append_substring( &whole_item, in, len1 );
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
sb_append_substring( &whole_item, sub_item2, item_len );
sb_append_char( &whole_item, INTERNAL_SEPARATOR );
sb_append( &whole_item, tail_item );
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_destroy( &tail_expand );
free( subcmd );
return 1;
}
@ -1246,7 +1244,7 @@ static int tilde_expand( wchar_t **ptr )
old_in = name_end;
char *name_str = wcs2str( name );
struct passwd *userinfo =
getpwnam( name_str );
@ -1397,7 +1395,7 @@ int expand_string( wchar_t *str,
for( i=0; i<al_get_count( in ); i++ )
{
wchar_t *next;
next = expand_unescape( (wchar_t *)al_get( in, i ),
1);

View file

@ -1007,12 +1007,13 @@ static int insert_str(wchar_t *str)
}
else
{
int old_len = data->buff_len;
data->buff_len += len;
check_size();
/* Insert space for extra character at the right position */
if( data->buff_pos < data->buff_len )
/* Insert space for extra characters at the right position */
if( data->buff_pos < old_len )
{
memmove( &data->buff[data->buff_pos+len],
&data->buff[data->buff_pos],

30
wutil.c
View file

@ -22,22 +22,37 @@
#include "common.h"
#include "wutil.h"
/**
Buffer for converting wide arguments to narrow arguments, used by
the \c wutil_wcs2str() function.
*/
static char *tmp=0;
/**
Length of the \c tmp buffer.
*/
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()
{
free( tmp );
tmp=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 )
{
c++;
wutil_calls++;
size_t new_sz =MAX_UTF8_BYTES*wcslen(in)+1;
if( tmp_len < new_sz )
@ -109,14 +124,17 @@ int wopen(const wchar_t *pathname, int flags, ...)
if( tmp )
{
va_start( argp, flags );
if( ! (flags & O_CREAT) )
{
res = open(tmp, flags);
}
else
{
va_start( argp, flags );
res = open(tmp, flags, va_arg(argp, int) );
va_end( argp );
va_end( argp );
}
}
return res;