From f5f15f9de25d3f38baa38d8bb49a162b3eb1e730 Mon Sep 17 00:00:00 2001 From: axel Date: Tue, 29 Aug 2006 01:19:13 +1000 Subject: [PATCH] Use dynamically sized buffer for reporting error messages in the parser darcs-hash:20060828151913-ac50b-02453c13d107f88023b2331bf40daf6d329ac597.gz --- parser.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/parser.c b/parser.c index a237d6932..f898a2df2 100644 --- a/parser.c +++ b/parser.c @@ -251,11 +251,6 @@ The fish parser. Contains functions for parsing code. #define UNKNOWN_BLOCK N_( L"unknown/invalid block" ) -/** - Size of the error string buffer -*/ -#define ERR_STR_SZ 1024 - /** Datastructure to describe a block type, like while blocks, command substitution blocks, etc. */ @@ -350,7 +345,7 @@ io_data_t *block_io; static int err_pos; /** Description of last error */ -static wchar_t err_str[ERR_STR_SZ]; +static string_buffer_t *err_buff=0; /** Pointer to the current tokenizer */ static tokenizer *current_tokenizer; @@ -756,11 +751,17 @@ void error( int ec, int p, const wchar_t *str, ... ) { va_list va; + if( !err_buff ) + err_buff = sb_halloc( global_context ); + + error_code = ec; err_pos = p; va_start( va, str ); - vswprintf( err_str, ERR_STR_SZ, str, va ); + + sb_vprintf( err_buff, str, va ); + va_end( va ); } @@ -1007,11 +1008,11 @@ void parser_destroy() */ static void print_errors( string_buffer_t *target, const wchar_t *prefix ) { - if( error_code ) + if( error_code && err_buff ) { int tmp; - sb_printf( target, L"%ls: %ls\n", prefix, err_str ); + sb_printf( target, L"%ls: %ls\n", prefix, (wchar_t *)err_buff->buff ); tmp = current_tokenizer_pos; current_tokenizer_pos = err_pos; @@ -1027,9 +1028,9 @@ static void print_errors( string_buffer_t *target, const wchar_t *prefix ) */ static void print_errors_stderr() { - if( error_code ) + if( error_code && err_buff ) { - debug( 0, L"%ls", err_str ); + debug( 0, L"%ls", (wchar_t *)err_buff->buff ); int tmp; tmp = current_tokenizer_pos;