Skip to content

Commit

Permalink
better guards on access tab index (#3821)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/392891325557410/1209158320724215/f
Tech Design URL:
CC:

**Description**:
Speculative fix for a crash. Checks index is available in indices before
accessing the array.

**Steps to test this PR**:
Smoke test tab manager on iPhone and iPad
1.  Grid and list mode
2. Add new tabs 
3. Delete tabs
4. Reorder tabs
5. Close and re-open the app
  • Loading branch information
brindy authored Jan 17, 2025
1 parent c66aea0 commit bfb6123
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
3 changes: 1 addition & 2 deletions DuckDuckGo/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ class TabManager {

@MainActor
func current(createIfNeeded: Bool = false) -> TabViewController? {
let index = model.currentIndex
let tab = model.tabs[index]
guard let tab = model.currentTab else { return nil }

if let controller = controller(for: tab) {
return controller
Expand Down
2 changes: 1 addition & 1 deletion DuckDuckGo/TabsModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class TabsModel: NSObject, NSCoding {

var currentTab: Tab? {
let index = currentIndex
return tabs[index]
return tabs.indices.contains(index) ? tabs[index] : nil
}

var count: Int {
Expand Down

0 comments on commit bfb6123

Please sign in to comment.