From c2f141007660d9777b24cdb851ecaa6a7744d295 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Fri, 25 Oct 2013 22:34:18 +0000 Subject: [PATCH] * Source/NSMenuView.m (-heightForItem:): Use -menuItemCellForItemAtIndex: to protect against an index being to big. This happens when the menu does not send notifications and a non-existing item gets highlighted. * Source/NSMenuView.m (-menuItemCellForItemAtIndex:): Protect against negative index values. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@37279 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 9 +++++++++ Source/NSMenuView.m | 12 +++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index b97478c84..fd8ce829c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2013-10-26 Fred Kiefer + + * Source/NSMenuView.m (-heightForItem:): Use + -menuItemCellForItemAtIndex: to protect against an index being to + big. This happens when the menu does not send notifications and a + non-existing item gets highlighted. + * Source/NSMenuView.m (-menuItemCellForItemAtIndex:): Protect + against negative index values. + 2013-10-20 Fred Kiefer * Source/NSBitmapImageRep+PNG.m: Better cleanup on error. diff --git a/Source/NSMenuView.m b/Source/NSMenuView.m index 87071d422..46f38816f 100644 --- a/Source/NSMenuView.m +++ b/Source/NSMenuView.m @@ -444,7 +444,7 @@ static float menuBarHeight = 0.0; - (NSMenuItemCell*) menuItemCellForItemAtIndex: (NSInteger)index { - if (index < [_itemCells count]) + if ((index >= 0) && (index < [_itemCells count])) return [_itemCells objectAtIndex: index]; else return nil; @@ -703,9 +703,10 @@ static float menuBarHeight = 0.0; - (CGFloat) heightForItem: (NSInteger)idx { - if (idx >= 0) + NSMenuItemCell *cell = [self menuItemCellForItemAtIndex: idx]; + + if (cell != nil) { - NSMenuItemCell *cell = [_itemCells objectAtIndex: idx]; NSMenuItem *item = [cell menuItem]; if ([item isSeparatorItem]) @@ -724,7 +725,7 @@ static float menuBarHeight = 0.0; if (item >= 0) { NSInteger i = 0; - for (i = (count - 1); i > item ; i--) + for (i = (count - 1); i > item; i--) { total += [self heightForItem: i]; } @@ -736,7 +737,8 @@ static float menuBarHeight = 0.0; { CGFloat total = 0; NSUInteger i = 0; - for (i = 0; i<[_itemCells count]; i++) + + for (i = 0; i < [_itemCells count]; i++) { total += [self heightForItem: i]; }