From 3349e32196cabc3fb1d2371cab4d8872fbfbdb28 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Mar 2017 10:09:14 -0800 Subject: [PATCH] Verify selectedIndex to prevent NSRangeException --- atom/browser/ui/cocoa/atom_touch_bar.mm | 3 ++- spec/api-touch-bar-spec.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/atom/browser/ui/cocoa/atom_touch_bar.mm b/atom/browser/ui/cocoa/atom_touch_bar.mm index 37dc6e7f187..d6f7c1c1d76 100644 --- a/atom/browser/ui/cocoa/atom_touch_bar.mm +++ b/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 diff --git a/spec/api-touch-bar-spec.js b/spec/api-touch-bar-spec.js index fa2c2a8eec0..a09e0314c42 100644 --- a/spec/api-touch-bar-spec.js +++ b/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'