Fix crash bug on invalid input to fish_pager

darcs-hash:20060224184050-ac50b-da122d893fa0e2aabbd48058c696e2815c4657ca.gz
This commit is contained in:
axel 2006-02-25 04:40:50 +10:00
parent dad2b93d1e
commit d2e11ea61d

View file

@ -305,10 +305,31 @@ int writembs( char *str )
int writech( wint_t ch ) int writech( wint_t ch )
{ {
static mbstate_t out_state; mbstate_t state;
char buff[MB_CUR_MAX];
size_t bytes = wcrtomb( buff, ch, &out_state );
int i; int i;
char buff[MB_CUR_MAX+1];
size_t bytes;
if( ( ch >= ENCODE_DIRECT_BASE) &&
( ch < ENCODE_DIRECT_BASE+256) )
{
buff[0] = ch- ENCODE_DIRECT_BASE;
bytes=1;
}
else
{
memset( &state, 0, sizeof(state) );
bytes= wcrtomb( buff, ch, &state );
switch( bytes )
{
case (size_t)(-1):
{
return 1;
}
}
}
for( i=0; i<bytes; i++ ) for( i=0; i<bytes; i++ )
{ {