Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db5c4fb8 authored by Craig Mautner's avatar Craig Mautner
Browse files

Fix incorrect looping limits.

One cannot iterate across an entire list if one both removes an entry
and increments the index into the list. Do one or the other or you
will end up with bugs like 11556768 which is now fixed.

Change-Id: I57f1ad13075a005cae3c1cbfae10e230d9af143a
parent 7791b84c
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -565,7 +565,7 @@ final class ActivityStack {

        // Move userId's tasks to the top.
        int index = mTaskHistory.size();
        for (int i = 0; i < index; ++i) {
        for (int i = 0; i < index; ) {
            TaskRecord task = mTaskHistory.get(i);
            if (task.userId == userId) {
                if (DEBUG_TASKS) Slog.d(TAG, "switchUserLocked: stack=" + getStackId() +
@@ -573,6 +573,9 @@ final class ActivityStack {
                mTaskHistory.remove(i);
                mTaskHistory.add(task);
                --index;
                // Use same value for i.
            } else {
                ++i;
            }
        }
        if (VALIDATE_TOKENS) {