Browse Source

Verify selectedIndex to prevent NSRangeException

Kevin Sawicki 8 years ago
parent
commit
3349e32196
2 changed files with 5 additions and 3 deletions
  1. 2 1
      atom/browser/ui/cocoa/atom_touch_bar.mm
  2. 3 2
      spec/api-touch-bar-spec.js

+ 2 - 1
atom/browser/ui/cocoa/atom_touch_bar.mm

@@ -465,7 +465,8 @@ static NSTouchBarItemIdentifier SegmentedControlIdentifier = @"com.electron.touc
 
   int selectedIndex = 0;
   settings.Get("selectedIndex", &selectedIndex);
-  control.selectedSegment = selectedIndex;
+  if (selectedIndex >= 0 && selectedIndex < control.segmentCount)
+    control.selectedSegment = selectedIndex;
 }
 
 @end

+ 3 - 2
spec/api-touch-bar-spec.js

@@ -45,8 +45,9 @@ describe('TouchBar module', function () {
         new TouchBarSegmentedControl({
           segmentStyle: 'capsule',
           segments: [{label: 'baz', enabled: false}],
-          selectedIndex: 0
-        })
+          selectedIndex: 5
+        }),
+        new TouchBarSegmentedControl({segments: []})
       ])
       window.setTouchBar(touchBar)
       label.label = 'baz'