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

@ -1123,8 +1123,6 @@ static int expand_subshell( wchar_t *in, array_list_t *out )
} }
len1 = (paran_begin-in); len1 = (paran_begin-in);
len2 = wcslen(paran_end)-1; len2 = wcslen(paran_end)-1;
prev=0; prev=0;

View file

@ -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],

28
wutil.c
View file

@ -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,15 +124,18 @@ 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;
} }