From d2e11ea61d23e8c12f2601c48781617f07d4b46e Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 25 Feb 2006 04:40:50 +1000 Subject: [PATCH] Fix crash bug on invalid input to fish_pager darcs-hash:20060224184050-ac50b-da122d893fa0e2aabbd48058c696e2815c4657ca.gz --- output.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/output.c b/output.c index f521fb9c8..0aea80c4e 100644 --- a/output.c +++ b/output.c @@ -305,10 +305,31 @@ int writembs( char *str ) int writech( wint_t ch ) { - static mbstate_t out_state; - char buff[MB_CUR_MAX]; - size_t bytes = wcrtomb( buff, ch, &out_state ); + mbstate_t state; 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