fix: clamp tab index in move_tab to prevent out-of-bounds insert#308
Open
enomado wants to merge 1 commit intoanhosh:mainfrom
Open
fix: clamp tab index in move_tab to prevent out-of-bounds insert#308enomado wants to merge 1 commit intoanhosh:mainfrom
enomado wants to merge 1 commit intoanhosh:mainfrom
Conversation
When reordering a tab within the same node, `remove_tab` is called before `insert_tab`. This reduces the tab count by one, so the original destination index may now be out of bounds. Clamp the insertion index to the current tab count to prevent panic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When reordering a tab within the same node via drag-and-drop,
DockState::move_tabcallsremove_tab(src_tab)beforeinsert_tab(index, tab). If the source and destination are the same node, this reduces the tab count by one — making the original destinationindexpotentially out of bounds.Example: A node has 3 tabs
[A, B, C]. Dragging tabB(index 1) to position 3 (the end):remove_tab(1)→ node becomes[A, C](count = 2)insert_tab(3, B)→ panic, index 3 > count 2Fix
Clamp the insertion index to the current tab count after removal. This is safe because inserting at
countis equivalent to appending — which is the correct semantic for "move to the end".Test plan