From: Joe Wreschnig Date: Tue, 26 Feb 2013 16:55:17 +0000 (+0100) Subject: Remove a branch that could never trigger (unsigned < 0) and some other logic errors... X-Git-Tag: version-1.0~124 X-Git-Url: https://git.yukkurigames.com/?a=commitdiff_plain;h=0e4bf29455987fd95d2eb2b88cdec407e86e4c9b;p=enjoyable.git Remove a branch that could never trigger (unsigned < 0) and some other logic errors leading to a potential access of array index '-1' when no row is selected. --- diff --git a/ConfigsController.m b/ConfigsController.m index 01bd0d3..ce58f07 100644 --- a/ConfigsController.m +++ b/ConfigsController.m @@ -23,10 +23,6 @@ -(void) restoreNeutralConfig { if(!neutralConfig) return; - if([configs indexOfObject:neutralConfig] < 0) {// deleted, keep what we have - neutralConfig = NULL; - return; - } [self activateConfig: neutralConfig forApplication: NULL]; } @@ -84,7 +80,8 @@ } -(void)tableViewSelectionDidChange:(NSNotification*) notify { - [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL]; + if (tableView.selectedRow < configs.count) + [self activateConfig: (Config*)[configs objectAtIndex:[tableView selectedRow]] forApplication: NULL]; } -(id) tableView: (NSTableView*)view objectValueForTableColumn: (NSTableColumn*) column row: (int) index { @@ -161,7 +158,7 @@ for(int i=0; i<[ary count]; i++) { NSDictionary* dict = [[ary objectAtIndex:i] objectForKey:@"entries"]; for(id key in dict) { - [[[newConfigs objectAtIndex:i] entries] + [[[newConfigs objectAtIndex:i] entries] setObject: [Target unstringify: [dict objectForKey: key] withConfigList: newConfigs] forKey: key]; } @@ -173,7 +170,8 @@ [(ApplicationController *)[[NSApplication sharedApplication] delegate] configsChanged]; int index = [[envelope objectForKey: @"selectedIndex"] intValue]; - [self activateConfig: [configs objectAtIndex:index] forApplication: NULL]; + if (index < configs.count) + [self activateConfig: [configs objectAtIndex:index] forApplication: NULL]; } -(void) applicationSwitchedTo: (NSString*) name withPsn: (ProcessSerialNumber) psn {