Fix bug in completion code reported by Martin Bähr, as well as other bug evident in his bug report.

darcs-hash:20060826013722-ac50b-08de084a40af8ba5d708a7cd162087b7afbb7648.gz
This commit is contained in:
axel 2006-08-26 11:37:22 +10:00
parent 0a603a56c6
commit 69537430ea
2 changed files with 30 additions and 12 deletions

View file

@ -455,6 +455,8 @@ static int builtin_set( wchar_t **argv )
int slice=0;
int i;
wchar_t *bad_char;
/* Parse options to obtain the requested operation and the modifiers */
woptind = 0;
@ -629,7 +631,7 @@ static int builtin_set( wchar_t **argv )
print_variables(0, 0, scope);
return 0;
}
if( !(dest = wcsdup(argv[woptind])))
{
DIE_MEM();
@ -649,6 +651,15 @@ static int builtin_set( wchar_t **argv )
return 1;
}
if( (bad_char = wcsvarname( dest ) ) )
{
sb_printf( sb_err, BUILTIN_ERR_VARCHAR, argv[0], *bad_char );
builtin_print_help( argv[0], sb_err );
free( dest );
return 1;
}
if( slice && erase && (scope != ENV_USER) )
{
free( dest );
@ -678,7 +689,7 @@ static int builtin_set( wchar_t **argv )
al_init(&result);
tokenize_variable_array( env_get(dest), &result );
for( ; woptind<argc; woptind++ )
{
if( !parse_index( &indexes, argv[woptind], dest, al_get_count( &result ) ) )

View file

@ -1820,20 +1820,27 @@ static int complete_variable( const wchar_t *var,
if( wcsncmp( var, name, varlen) == 0 )
{
wchar_t *value = expand_escape_variable( env_get( name ));
wchar_t *value_unescaped, *value;
wchar_t *blarg;
/*
Variable description is 'Variable: VALUE
*/
blarg = wcsdupcat2( &name[varlen], COMPLETE_SEP_STR, COMPLETE_VAR_DESC_VAL, value, 0 );
if( blarg )
value_unescaped = env_get( name );
if( value_unescaped )
{
res =1;
al_push( comp, blarg );
value = expand_escape_variable( value_unescaped );
/*
Variable description is 'Variable: VALUE
*/
blarg = wcsdupcat2( &name[varlen], COMPLETE_SEP_STR, COMPLETE_VAR_DESC_VAL, value, 0 );
if( blarg )
{
res =1;
al_push( comp, blarg );
}
free( value );
}
free( value );
}
}