mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-05 08:11:15 -03:00
Fix bug when using same array index more than once in a single array expansion, e.g. $PATH[1 1 1]
darcs-hash:20060731164816-ac50b-d3fc56b425035a4cbcf93a91435f9df9ca5997ac.gz
This commit is contained in:
14
expand.c
14
expand.c
@@ -892,7 +892,12 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
|||||||
{
|
{
|
||||||
tmp = al_get_count( &var_item_list)+tmp+1;
|
tmp = al_get_count( &var_item_list)+tmp+1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Check that we are within array
|
||||||
|
bounds. If not, truncate the list to
|
||||||
|
exit.
|
||||||
|
*/
|
||||||
if( tmp < 1 || tmp > al_get_count( &var_item_list ) )
|
if( tmp < 1 || tmp > al_get_count( &var_item_list ) )
|
||||||
{
|
{
|
||||||
error( SYNTAX_ERROR,
|
error( SYNTAX_ERROR,
|
||||||
@@ -904,12 +909,11 @@ static int expand_variables( wchar_t *in, array_list_t *out, int last_idx )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Move string from list l to list idx */
|
/* Replace each index in var_idx_list inplace with the string value at the specified index */
|
||||||
al_set( var_idx_list, j, al_get( &var_item_list, tmp-1 ) );
|
al_set( var_idx_list, j, wcsdup(al_get( &var_item_list, tmp-1 ) ) );
|
||||||
al_set( &var_item_list, tmp-1, 0 );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Free remaining strings in list l and truncate it */
|
/* Free strings in list var_item_list and truncate it */
|
||||||
al_foreach( &var_item_list, &free );
|
al_foreach( &var_item_list, &free );
|
||||||
al_truncate( &var_item_list, 0 );
|
al_truncate( &var_item_list, 0 );
|
||||||
/* Add items from list idx back to list l */
|
/* Add items from list idx back to list l */
|
||||||
|
|||||||
Reference in New Issue
Block a user