From 24837e4f269c7ad44c555066d7f5d3d9c4d2c139 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Wed, 11 Jan 2012 23:03:33 +0000 Subject: Protect against dodgy preference data that may case bounds exceptions when selecting the default favorite in the general preference pane. --- Source/SPGeneralPreferencePane.h | 2 +- Source/SPGeneralPreferencePane.m | 8 +++++--- Source/SPPreferenceController.m | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'Source') diff --git a/Source/SPGeneralPreferencePane.h b/Source/SPGeneralPreferencePane.h index 76343a83..a23b6bb8 100644 --- a/Source/SPGeneralPreferencePane.h +++ b/Source/SPGeneralPreferencePane.h @@ -42,6 +42,6 @@ - (IBAction)updateDefaultFavorite:(id)sender; - (void)updateDefaultFavoritePopup; -- (void)resetDefaultFavoritePopupSelection; +- (void)updateDefaultFavoritePopupSelection; @end diff --git a/Source/SPGeneralPreferencePane.m b/Source/SPGeneralPreferencePane.m index b87d6ab8..67c43881 100644 --- a/Source/SPGeneralPreferencePane.m +++ b/Source/SPGeneralPreferencePane.m @@ -77,15 +77,17 @@ [editMenuItem release]; // Select the default favorite from prefs - [defaultFavoritePopup selectItemAtIndex:(![prefs boolForKey:SPSelectLastFavoriteUsed]) ? ([prefs integerForKey:SPDefaultFavorite] + 2) : 0]; + [self updateDefaultFavoritePopupSelection]; } /** * Resets the default favorite popup button selection based on the user's preferences. */ -- (void)resetDefaultFavoritePopupSelection +- (void)updateDefaultFavoritePopupSelection { - [defaultFavoritePopup selectItemAtIndex:(![prefs boolForKey:SPSelectLastFavoriteUsed]) ? ([prefs integerForKey:SPDefaultFavorite] + 2) : 0]; + NSUInteger index = [prefs integerForKey:SPDefaultFavorite]; + + [defaultFavoritePopup selectItemAtIndex:(![prefs boolForKey:SPSelectLastFavoriteUsed] && index > 0 && index < [[defaultFavoritePopup itemArray] count]) ? index + 2 : 0]; } #pragma mark - diff --git a/Source/SPPreferenceController.m b/Source/SPPreferenceController.m index ed0d0ebe..0d6d46aa 100644 --- a/Source/SPPreferenceController.m +++ b/Source/SPPreferenceController.m @@ -145,7 +145,7 @@ // Set the default favorite popup back to preference if ([sender isKindOfClass:[NSMenuItem class]]) { - [generalPreferencePane resetDefaultFavoritePopupSelection]; + [generalPreferencePane updateDefaultFavoritePopupSelection]; } } -- cgit v1.2.3