From 929519cb0f2be3dce760c77b4d3d651eed2d4a6a Mon Sep 17 00:00:00 2001 From: axel Date: Sat, 8 Oct 2005 12:00:08 +1000 Subject: [PATCH] Minor edits darcs-hash:20051008020008-ac50b-401f0e36582075d177afb2f1573c765c572f1a97.gz --- common.c | 10 ++++++---- parser.c | 21 +++++++++++++++++++-- tokenizer.c | 10 ++++++++-- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/common.c b/common.c index 00545f90b..a387b82ed 100644 --- a/common.c +++ b/common.c @@ -275,7 +275,7 @@ void error_reset() char *wcs2str( const wchar_t *in ) { c5++; - + char *res = malloc( MAX_UTF8_BYTES*wcslen(in)+1 ); if( res == 0 ) { @@ -317,7 +317,7 @@ char **wcsv2strv( const wchar_t **in ) wchar_t *wcsdupcat( const wchar_t *a, const wchar_t *b ) { c1++; - + return wcsdupcat2( a, b, 0 ); } @@ -580,13 +580,15 @@ wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) wchar_t *wcsdup( const wchar_t *in ) { - wchar_t *out = malloc( sizeof( wchar_t)*(wcslen(in)+1)); + size_t len=wcslen(in); + wchar_t *out = malloc( sizeof( wchar_t)*(len+1)); if( out == 0 ) { die_mem(); } - wcscpy( out, in ); + + memcpy( out, in, sizeof( wchar_t)*(len+1)); return out; } diff --git a/parser.c b/parser.c index 0a4f83d7f..0132c2d2c 100644 --- a/parser.c +++ b/parser.c @@ -72,6 +72,9 @@ The fish parser. Contains functions for parsing code. */ #define RECURSION_ERR_MSG L"Maximum recursion depth reached. Accidental infinite loop?" +/** + Error message used when the end of a block can't be located +*/ #define BLOCK_END_ERR_MSG L"Could not locate end of block. The 'end' command may be missing or misspelled." /** @@ -126,12 +129,20 @@ io_data_t *block_io; */ static array_list_t profile_data; +/** + Keeps track of how many recursive eval calls have been made. Eval + doesn't call itself directly, recursion happens on blocks and on + command substitutions. +*/ static int eval_level=-1; static int parse_job( process_t *p, job_t *j, tokenizer *tok ); +/** + Struct used to keep track of profiling data for a command +*/ typedef struct { int exec, parse, level, skipped; @@ -340,6 +351,9 @@ int parser_is_pipe_forbidden( wchar_t *word ) (void *)0 ); } +/** + Search the text for the end of the current block +*/ static const wchar_t *parser_find_end( const wchar_t * buff ) { tokenizer tok; @@ -709,6 +723,9 @@ void parser_destroy() al_destroy( &forbidden_function ); } +/** + Print error message if an error has occured while parsing +*/ static void print_errors() { if( error_code ) @@ -1643,7 +1660,7 @@ static void eval_job( tokenizer *tok ) long long t1=0, t2=0, t3=0; profile_element_t *p=0; int skip = 0; - + if( profile ) { p=malloc( sizeof(profile_element_t)); @@ -1947,7 +1964,7 @@ int parser_test( wchar_t * buff, int require_additional_commands=0; current_tokenizer = &tok; - + for( tok_init( &tok, buff, 0 ); tok_has_next( &tok ) && !err; tok_next( &tok ) ) diff --git a/tokenizer.c b/tokenizer.c index 5f006ee2d..6a012fe21 100644 --- a/tokenizer.c +++ b/tokenizer.c @@ -53,6 +53,12 @@ \return 0 if the system could not provide the memory needed, and 1 otherwise. */ + +/** + Maximum length of a string containing a file descriptor number +*/ +#define FD_STR_MAX_LEN 16 + const static wchar_t *tok_desc[] = { L"Tokenizer not yet initialized", @@ -546,9 +552,9 @@ void tok_next( tokenizer *tok ) tok_error( tok, PIPE_ERROR ); return; } - check_size( tok, 16 ); + check_size( tok, FD_STR_MAX_LEN ); tok->buff++; - swprintf( tok->last, 16, L"%d", fd ); + swprintf( tok->last, FD_STR_MAX_LEN, L"%d", fd ); tok->last_type = TOK_PIPE; return; }