Fix a number of bugs found using the warnings generated by earlier patch

darcs-hash:20061019153603-ac50b-4efb1ad1fe2cbe693a921648a0616a3d258d7933.gz
This commit is contained in:
axel 2006-10-20 01:36:03 +10:00
parent ae16397e1c
commit 4683f4c989
8 changed files with 188 additions and 155 deletions

View file

@ -909,24 +909,26 @@ static const wchar_t *complete_get_desc_suffix( const wchar_t *suff_orig )
array_list_t l;
al_init( &l );
exec_subshell( cmd, &l );
free(cmd);
if( al_get_count( &l )>0 )
if( exec_subshell( cmd, &l ) != -1 )
{
wchar_t *ln = (wchar_t *)al_get(&l, 0 );
if( wcscmp( ln, L"unknown" ) != 0 )
if( al_get_count( &l )>0 )
{
desc = wcsdup( ln);
/*
I have decided I prefer to have the description
begin in uppercase and the whole universe will just
have to accept it. Hah!
*/
desc[0]=towupper(desc[0]);
wchar_t *ln = (wchar_t *)al_get(&l, 0 );
if( wcscmp( ln, L"unknown" ) != 0 )
{
desc = wcsdup( ln);
/*
I have decided I prefer to have the description
begin in uppercase and the whole universe will just
have to accept it. Hah!
*/
desc[0]=towupper(desc[0]);
}
}
}
free(cmd);
al_foreach( &l, &free );
al_destroy( &l );
}
@ -1155,76 +1157,79 @@ static void complete_cmd_desc( const wchar_t *cmd, array_list_t *comp )
systems with a large set of manuals, but it should be ok
since apropos is only called once.
*/
exec_subshell( lookup_cmd, &list );
/*
Then discard anything that is not a possible completion and put
the result into a hashtable with the completion as key and the
description as value.
Should be reasonably fast, since no memory allocations are needed.
*/
for( i=0; i<al_get_count( &list); i++ )
if( exec_subshell( lookup_cmd, &list ) != -1 )
{
wchar_t *el = (wchar_t *)al_get( &list, i );
wchar_t *key, *key_end, *val_begin;
if( !el )
continue;
key = el+wcslen(cmd_start);
key_end = wcschr( el, L'\t' );
if( !key_end )
continue;
*key_end = 0;
val_begin = key_end+1;
/*
And once again I make sure the first character is uppercased
because I like it that way, and I get to decide these
things.
Then discard anything that is not a possible completion and put
the result into a hashtable with the completion as key and the
description as value.
Should be reasonably fast, since no memory allocations are needed.
*/
val_begin[0]=towupper(val_begin[0]);
hash_put( &lookup, key, val_begin );
}
/*
Then do a lookup on every completion and if a match is found,
change to the new description.
This needs to do a reallocation for every description added, but
there shouldn't be that many completions, so it should be ok.
*/
for( i=0; i<al_get_count(comp); i++ )
{
wchar_t *el = (wchar_t *)al_get( comp, i );
wchar_t *cmd_end = wcschr( el,
COMPLETE_SEP );
wchar_t *new_desc;
if( cmd_end )
*cmd_end = 0;
new_desc = (wchar_t *)hash_get( &lookup,
el );
if( new_desc )
for( i=0; i<al_get_count( &list); i++ )
{
wchar_t *new_el = wcsdupcat2( el,
COMPLETE_SEP_STR,
new_desc,
(void *)0 );
wchar_t *el = (wchar_t *)al_get( &list, i );
wchar_t *key, *key_end, *val_begin;
al_set( comp, i, new_el );
free( el );
if( !el )
continue;
key = el+wcslen(cmd_start);
key_end = wcschr( el, L'\t' );
if( !key_end )
continue;
*key_end = 0;
val_begin = key_end+1;
/*
And once again I make sure the first character is uppercased
because I like it that way, and I get to decide these
things.
*/
val_begin[0]=towupper(val_begin[0]);
hash_put( &lookup, key, val_begin );
}
else
/*
Then do a lookup on every completion and if a match is found,
change to the new description.
This needs to do a reallocation for every description added, but
there shouldn't be that many completions, so it should be ok.
*/
for( i=0; i<al_get_count(comp); i++ )
{
wchar_t *el = (wchar_t *)al_get( comp, i );
wchar_t *cmd_end = wcschr( el,
COMPLETE_SEP );
wchar_t *new_desc;
if( cmd_end )
*cmd_end = COMPLETE_SEP;
*cmd_end = 0;
new_desc = (wchar_t *)hash_get( &lookup,
el );
if( new_desc )
{
wchar_t *new_el = wcsdupcat2( el,
COMPLETE_SEP_STR,
new_desc,
(void *)0 );
al_set( comp, i, new_el );
free( el );
}
else
{
if( cmd_end )
*cmd_end = COMPLETE_SEP;
}
}
}
@ -1448,29 +1453,29 @@ static void complete_from_args( const wchar_t *str,
strings should be escaped!
*/
/*
for( i=0; i< al_get_count( &possible_comp ); i++ )
{
wchar_t *next = (wchar_t *)al_get( &possible_comp, i );
wchar_t *next_unescaped;
if( next )
{
next_unescaped = unescape( next, 0 );
if( next_unescaped )
{
al_set( &possible_comp , i, next_unescaped );
}
else
{
al_set( &possible_comp , i, 0 );
debug( 2, L"Could not expand string %ls on line %d of file %s", next, __LINE__, __FILE__ );
}
free( next );
}
else
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
}
}
for( i=0; i< al_get_count( &possible_comp ); i++ )
{
wchar_t *next = (wchar_t *)al_get( &possible_comp, i );
wchar_t *next_unescaped;
if( next )
{
next_unescaped = unescape( next, 0 );
if( next_unescaped )
{
al_set( &possible_comp , i, next_unescaped );
}
else
{
al_set( &possible_comp , i, 0 );
debug( 2, L"Could not expand string %ls on line %d of file %s", next, __LINE__, __FILE__ );
}
free( next );
}
else
{
debug( 2, L"Got null string on line %d of file %s", __LINE__, __FILE__ );
}
}
*/
copy_strings_with_prefix( comp_out, str, desc, 0, &possible_comp );
@ -1798,16 +1803,18 @@ static void complete_param_expand( wchar_t *str,
{
comp_str = str;
}
/*
debug( 3,
L"expand_string( \"%ls\", comp_out, EXPAND_SKIP_CMDSUBST | ACCEPT_INCOMPLETE | %ls );",
comp_str,
do_file?L"0":L"EXPAND_SKIP_WILDCARDS" );
*/
expand_string( 0,
wcsdup(comp_str),
comp_out,
EXPAND_SKIP_CMDSUBST | ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) );
if( expand_string( 0,
wcsdup(comp_str),
comp_out,
EXPAND_SKIP_CMDSUBST | ACCEPT_INCOMPLETE | (do_file?0:EXPAND_SKIP_WILDCARDS) ) )
{
/*
Ignore errors - completions may fail, and that's ok
*/
}
}
/**
@ -1974,7 +1981,7 @@ static int try_complete_user( const wchar_t *cmd,
L"/",
COMPLETE_SEP_STR,
COMPLETE_USER_DESC,
0 );
(void *)0 );
if( blarg != 0 )
{
al_push( comp, blarg );

12
exec.c
View file

@ -1344,7 +1344,7 @@ int exec_subshell( const wchar_t *cmd,
debug( 1,
_( L"Sent null command to subshell. This is a fish bug. If it can be reproduced, please send a bug report to %s." ),
PACKAGE_BUGREPORT );
return 0;
return -1;
}
is_subshell=1;
@ -1352,11 +1352,17 @@ int exec_subshell( const wchar_t *cmd,
prev_status = proc_get_last_status();
eval( cmd, io_buffer, SUBST );
if( eval( cmd, io_buffer, SUBST ) )
{
status = -1;
}
else
{
status = proc_get_last_status();
}
io_buffer_read( io_buffer );
status = proc_get_last_status();
proc_set_last_status( prev_status );
is_subshell = prev_subshell;

View file

@ -1265,7 +1265,12 @@ static int expand_cmdsubst( wchar_t *in, array_list_t *out )
wcslcpy( subcmd, paran_begin+1, paran_end-paran_begin );
subcmd[ paran_end-paran_begin-1]=0;
exec_subshell( subcmd, sub_res);
if( exec_subshell( subcmd, sub_res) == -1 )
{
halloc_free( context );
error( CMDSUBST_ERROR, -1, L"Unknown error while evaulating command substitution" );
return 0;
}
tail_begin = paran_end + 1;
if( *tail_begin == L'[' )

View file

@ -1297,6 +1297,7 @@ static void add_common_bindings()
add_escaped_mapping( name[i], (L"\\C-y"), L"Control-y", L"yank" );
add_mapping( name[i], L"", L"Any key", L"self-insert" );
}
}
/**

76
kill.c
View file

@ -97,7 +97,13 @@ void kill_add( wchar_t *str )
{
wchar_t *escaped_str = escape( str, 1 );
wchar_t *cmd = wcsdupcat2(L"echo ", escaped_str, L"|xsel -b",(void *)0);
exec_subshell( cmd, 0 );
if( exec_subshell( cmd, 0 ) == -1 )
{
/*
Do nothing on failiure
*/
}
free( cut_buffer );
free( cmd );
@ -192,49 +198,51 @@ static void kill_check_x_buffer()
wchar_t *new_cut_buffer=0;
array_list_t list;
al_init( &list );
exec_subshell( cmd, &list );
for( i=0; i<al_get_count( &list ); i++ )
if( exec_subshell( cmd, &list ) != -1 )
{
wchar_t *next_line = escape( (wchar_t *)al_get( &list, i ), 0 );
if( i==0 )
{
new_cut_buffer = next_line;
}
else
{
wchar_t *old = new_cut_buffer;
new_cut_buffer= wcsdupcat2( new_cut_buffer, L"\\n", next_line, (void *)0 );
free( old );
free( next_line );
}
}
if( new_cut_buffer )
{
/*
The buffer is inserted with backslash escapes,
since we don't really like tabs, newlines,
etc. anyway.
*/
if( cut_buffer != 0 )
for( i=0; i<al_get_count( &list ); i++ )
{
if( wcscmp( new_cut_buffer, cut_buffer ) == 0 )
wchar_t *next_line = escape( (wchar_t *)al_get( &list, i ), 0 );
if( i==0 )
{
free( new_cut_buffer );
new_cut_buffer = 0;
new_cut_buffer = next_line;
}
else
{
free( cut_buffer );
cut_buffer = 0;
wchar_t *old = new_cut_buffer;
new_cut_buffer= wcsdupcat2( new_cut_buffer, L"\\n", next_line, (void *)0 );
free( old );
free( next_line );
}
}
if( cut_buffer == 0 )
if( new_cut_buffer )
{
cut_buffer = new_cut_buffer;
kill_add_internal( cut_buffer );
/*
The buffer is inserted with backslash escapes,
since we don't really like tabs, newlines,
etc. anyway.
*/
if( cut_buffer != 0 )
{
if( wcscmp( new_cut_buffer, cut_buffer ) == 0 )
{
free( new_cut_buffer );
new_cut_buffer = 0;
}
else
{
free( cut_buffer );
cut_buffer = 0;
}
}
if( cut_buffer == 0 )
{
cut_buffer = new_cut_buffer;
kill_add_internal( cut_buffer );
}
}
}

View file

@ -878,7 +878,13 @@ static int parse_util_load_internal( const wchar_t *cmd,
/*
Source the completion file for the specified completion
*/
exec_subshell( src_cmd, 0 );
if( exec_subshell( src_cmd, 0 ) == -1 )
{
/*
Do nothing on failiure
*/
}
free(src_cmd);
reloaded = 1;
}

View file

@ -2910,7 +2910,7 @@ int parser_test( const wchar_t * buff,
*/
if( contains_str( cmd,
L"end",
0 ) )
(void *)0 ) )
{
err=1;
if( out )
@ -2985,7 +2985,7 @@ int parser_test( const wchar_t * buff,
if( contains_str( cmd,
L"or",
L"and",
0 ) )
(void *)0 ) )
{
/*
'or' and 'and' can not be used inside pipelines