commit:     cb7db35b2863967c327d76b1f8ec4dc77493ed7b
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Apr 17 10:46:33 2019 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Apr 17 10:47:11 2019 +0000
URL:        
https://gitweb.gentoo.org/proj/eselect-python.git/commit/?id=cb7db35b

Fix mismatched indexes when looping over old impls

Bug: https://bugs.gentoo.org/683178
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 python.eselect.in | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/python.eselect.in b/python.eselect.in
index 8c48b09..98b8cc9 100644
--- a/python.eselect.in
+++ b/python.eselect.in
@@ -182,7 +182,8 @@ do_cleanup() {
        local prefs=( $(get_all_preferences) )
 
        local i target_idx
-       for (( i = 0; i < ${#prefs[@]}; ++i )); do
+       local num_prefs=${#prefs[@]}
+       for (( i = 0; i < num_prefs; ++i )); do
                # remove preferences for uninstalled interpreters
                if ! has "${prefs[i]#-}" "${installed[@]}"; then
                        unset 'prefs[i]'
@@ -419,7 +420,8 @@ do_set() {
        local prefs=( $(get_all_preferences) )
 
        local i target_idx
-       for (( i = 0; i < ${#prefs[@]}; ++i )); do
+       local num_prefs=${#prefs[@]}
+       for (( i = 0; i < num_prefs; ++i )); do
                # find first positive preference matching the filter
                if [[ ! ${target_idx} ]]; then
                        if [[ ( ${filter} == --py? && ${prefs[i]} == 
python${filter:4}* ) \
@@ -433,7 +435,7 @@ do_set() {
                [[ ${prefs[i]#-} == ${target} ]] && unset 'prefs[i]'
        done
        # if none matched, add to the bottom
-       : "${target_idx=${#prefs[@]}}"
+       : "${target_idx=${num_prefs}}"
 
        # add between remaining preferences, before the one matching
        # need to do this outta loop in case no pref matches

Reply via email to