From 62767971ee9d79f8e90e29caf53521dfc6f0a655 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Thu, 1 Sep 2022 18:35:33 -0400 Subject: [PATCH] don't crash if a slot is empty (laser3000, which has no slots and no disk drives) --- Ample/Slot.m | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Ample/Slot.m b/Ample/Slot.m index 89daef4..a4286ad 100644 --- a/Ample/Slot.m +++ b/Ample/Slot.m @@ -131,11 +131,15 @@ static NSDictionary *IndexMap = nil; -(SlotOption *)selectedItem { if (_selectedIndex < 0) return nil; + if (_selectedIndex >= [_options count]) return nil; + return [_options objectAtIndex: _selectedIndex]; } -(NSArray *)args { if (_selectedIndex < 0) return nil; + if (_selectedIndex >= [_options count]) return nil; + NSMutableArray *rv = [NSMutableArray new]; SlotOption *option = [_options objectAtIndex: _selectedIndex]; @@ -145,6 +149,8 @@ static NSDictionary *IndexMap = nil; -(NSDictionary *)serialize { if (_selectedIndex < 0) return nil; + if (_selectedIndex >= [_options count]) return nil; + NSMutableDictionary *d = [NSMutableDictionary new]; SlotOption *option = [_options objectAtIndex: _selectedIndex]; @@ -209,6 +215,7 @@ static NSDictionary *IndexMap = nil; -(Media)selectedMedia { if (_selectedIndex < 0) return EmptyMedia; + if (_selectedIndex >= [_options count]) return EmptyMedia; Media media = { 0 }; SlotOption *option = [_options objectAtIndex: _selectedIndex]; @@ -221,6 +228,8 @@ static NSDictionary *IndexMap = nil; -(NSArray *)selectedChildren { if (_selectedIndex < 0) return nil; + if (_selectedIndex >= [_options count]) return nil; + return [[_options objectAtIndex: _selectedIndex] children]; }