diff --git a/common.c b/common.c index e39febd1e..d1d2fe21a 100644 --- a/common.c +++ b/common.c @@ -212,8 +212,13 @@ wchar_t *str2wcs( const char *in ) size_t len = strlen(in); out = malloc( sizeof(wchar_t)*(len+1) ); + + if( !out ) + { + die_mem(); + } + return str2wcs_internal( in, out ); - } wchar_t *str2wcs_internal( const char *in, wchar_t *out ) @@ -226,11 +231,6 @@ wchar_t *str2wcs_internal( const char *in, wchar_t *out ) memset( &state, 0, sizeof(state) ); - if( !out ) - { - die_mem(); - } - while( in[in_pos] ) { res = mbrtowc( &out[out_pos], &in[in_pos], len-in_pos, &state ); diff --git a/complete.c b/complete.c index 1e9321517..d3de7dd06 100644 --- a/complete.c +++ b/complete.c @@ -481,8 +481,10 @@ void complete_remove( const wchar_t *cmd, { wchar_t *pos2 = pos+1; while( *pos2 == L':' ) + { pos2++; - + } + memmove( pos, pos2, sizeof(wchar_t)*wcslen(pos2) ); @@ -500,7 +502,9 @@ void complete_remove( const wchar_t *cmd, free( o ); } else + { oprev = o; + } } } @@ -523,7 +527,9 @@ void complete_remove( const wchar_t *cmd, } if( e ) + { eprev = e; + } } } @@ -541,8 +547,14 @@ static void parse_cmd_string( const wchar_t *str, /* Get the path of the command */ path = get_filename( str ); if( path == 0 ) + { + /** + Use the empty string as the 'path' for commands that can + not be found. + */ path = wcsdup(L""); - + } + /* Make sure the path is not included in the command */ cmd = wcsrchr( str, L'/' ); if( cmd != 0 ) @@ -611,11 +623,11 @@ int complete_is_valid_option( const wchar_t *str, return 0; } - - if( !(short_validated = malloc( wcslen( opt ) ))) + { die_mem(); - + } + memset( short_validated, 0, wcslen( opt ) ); hash_init( &gnu_match_hash, @@ -649,8 +661,10 @@ int complete_is_valid_option( const wchar_t *str, const wchar_t *a; if( !wildcard_match( match, i->cmd ) ) + { continue; - + } + found_match = 1; if( !i->authorative ) @@ -666,15 +680,19 @@ int complete_is_valid_option( const wchar_t *str, for( o = i->first_option; o; o=o->next ) { if( o->old_mode ) + { continue; - + } + if( wcsncmp( &opt[2], o->long_opt, gnu_opt_len )==0) { hash_put( &gnu_match_hash, o->long_opt, L"" ); if( (wcsncmp( &opt[2], o->long_opt, wcslen( o->long_opt) )==0) ) + { is_gnu_exact=1; + } } } } @@ -926,24 +944,30 @@ const wchar_t *complete_get_desc( const wchar_t *filename ) switch( errno ) { case ENOENT: + { sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_ROTTEN_SYMLINK_DESC ); break; - + } + case EACCES: + { break; - + } + default: + { if( errno == ELOOP ) { sb_printf( get_desc_buff, L"%lc%ls", COMPLETE_SEP, COMPLETE_LOOP_SYMLINK_DESC ); } /* - Some kind of broken symlink. We ignore it - here, and it will get a 'file' description, - or one based on suffix. + Some kind of unknown broken symlink. We + ignore it here, and it will get a 'file' + description, or one based on suffix. */ break; + } } } @@ -1013,19 +1037,14 @@ static void copy_strings_with_prefix( array_list_t *comp_out, if(!tmp) return; - if( tmp[0] == L'~' ) - { - tmp=expand_tilde(wc); - } - wc = parse_util_unescape_wildcards( tmp ); free(tmp); for( i=0; i= 0 && tmp <=10 && !*end ) + { + debug_level=tmp; + } + else + { + debug( 0, _(L"Invalid value '%s' for debug level switch"), optarg ); + exit(1); + } + break; + } + case 'h': cmd = "help"; break; @@ -233,7 +253,7 @@ int main( int argc, char **argv ) wchar_t *cmd_wcs = str2wcs( cmd ); res = eval( cmd_wcs, 0, TOP ); free(cmd_wcs); - reader_exit(0); + reader_exit(0); } else { diff --git a/parse_util.c b/parse_util.c index 57f36b027..18ffad8a2 100644 --- a/parse_util.c +++ b/parse_util.c @@ -155,16 +155,12 @@ int parse_util_locate_cmdsubst( const wchar_t *in, return 0; } - *begin = paran_begin; - *end = paran_count?in+wcslen(in):paran_end; + if( begin ) + *begin = paran_begin; + if( end ) + *end = paran_count?in+wcslen(in):paran_end; -/* assert( *begin >= in ); - assert( *begin < (in+wcslen(in) ) ); - assert( *end >= *begin ); - assert( *end < (in+wcslen(in) ) ); -*/ return 1; - } diff --git a/parser.c b/parser.c index bf339e778..c6b0b8d36 100644 --- a/parser.c +++ b/parser.c @@ -708,7 +708,7 @@ wchar_t *get_filename( const wchar_t *cmd ) { wchar_t *path; - debug( 2, L"get_filename( '%ls' )", cmd ); + debug( 3, L"get_filename( '%ls' )", cmd ); if(wcschr( cmd, L'/' ) != 0 ) { @@ -948,7 +948,14 @@ int eval_args( const wchar_t *line, array_list_t *args ) { case TOK_STRING: { - if( expand_string( 0, wcsdup(tok_last( &tok )), args, 0 ) == EXPAND_ERROR ) + wchar_t *tmp = wcsdup(tok_last( &tok )); + + if( !tmp ) + { + die_mem(); + } + + if( expand_string( 0, tmp, args, 0 ) == EXPAND_ERROR ) { err_pos=tok_get_pos( &tok ); do_loop=0; diff --git a/reader.c b/reader.c index f1301277f..8e87b5d61 100644 --- a/reader.c +++ b/reader.c @@ -567,11 +567,12 @@ static void remove_duplicates( array_list_t *l ) prev = (wchar_t *)al_get( l, 0 ); for( in=1, out=1; in < al_get_count( l ); in++ ) - { + { wchar_t *curr = (wchar_t *)al_get( l, in ); + if( fldcmp( prev, curr )==0 ) { - free( curr ); + free( curr ); } else { @@ -2036,7 +2037,6 @@ void reader_set_buffer( wchar_t *b, int p ) else { data->buff_pos=l; -// fwprintf( stderr, L"Pos %d\n", l ); } reader_super_highlight_me_plenty( data->buff, diff --git a/wildcard.c b/wildcard.c index fae759708..7c31f6a1f 100644 --- a/wildcard.c +++ b/wildcard.c @@ -151,13 +151,32 @@ static int wildcard_complete_internal( const wchar_t *orig, const wchar_t *(*desc_func)(const wchar_t *), array_list_t *out ) { + if( !wc ) + { + debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); + return 0; + } + + if( !str ) + { + debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); + return 0; + } + + if( !orig ) + { + debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ ); + return 0; + } + if( *wc == 0 && ( ( *str != L'.') || (!is_first)) ) { - if( !out ) - return 1; - wchar_t *new; + if( !out ) + { + return 1; + } if( wcschr( str, PROG_COMPLETE_SEP ) ) { @@ -165,7 +184,7 @@ static int wildcard_complete_internal( const wchar_t *orig, This completion has an embedded description, du not use the generic description */ wchar_t *sep; - + new = wcsdup( str ); sep = wcschr(new, PROG_COMPLETE_SEP ); *sep = COMPLETE_SEP; @@ -661,15 +680,19 @@ int wildcard_expand( const wchar_t *wc, if( wc_end ) { new_wc=wc_end+1; + /* + Accept multiple '/' as a single direcotry separator + */ while(*new_wc==L'/') + { new_wc++; + } } res |= wildcard_expand( new_wc, new_dir, flags, out ); - } /* @@ -694,8 +717,10 @@ int wildcard_expand( const wchar_t *wc, closedir( dir ); if( flags & ACCEPT_INCOMPLETE ) + { sb_destroy( &sb_desc ); - + } + return res; }