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);
len2 = wcslen(paran_end)-1;
prev=0;

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

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