Skip to content

Commit eb27e48

Browse files
committed
Nice bug fix. Ouch. Uninitialized values could assign shortcuts randomly. Where was the clang analyzer when I needed it?
1 parent a0a35b3 commit eb27e48

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

Diff for: SSYShortcutActuator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#import <Cocoa/Cocoa.h>
2-
#import "SRCommon.h" // for KeyCombo
2+
#import "SRCommon.h" // for KeyCombo, also this imports <Carbon/Carbon.h>
33

44
extern NSString* const SSYShortcutActuatorDidNonemptyNotification ;
55
extern NSString* const SSYShortcutActuatorDidEmptyNotification ;

Diff for: SSYShortcutActuator.m

+5-10
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ + (SSYShortcutActuator*)sharedActuator {
483483

484484
- (KeyCombo)keyComboForSelectorName:(NSString*)selectorName {
485485
KeyCombo keyCombo ;
486+
// Fixed in BookMacster 1.18.0 so garbage values are not returned if
487+
// shortcutInfos (below) comes up nil from user defaults.
488+
keyCombo.code = -1 ;
489+
keyCombo.flags = 0 ;
490+
486491
NSUserDefaults* sud = [NSUserDefaults standardUserDefaults] ;
487492
// Use -respondsToSelector: since one should never trust anything
488493
// that comes out of user defaults
@@ -496,21 +501,11 @@ - (KeyCombo)keyComboForSelectorName:(NSString*)selectorName {
496501
if ([number respondsToSelector:@selector(integerValue)]) {
497502
keyCombo.code = [number integerValue] ;
498503
}
499-
else {
500-
keyCombo.code = -1 ;
501-
}
502504

503505
number = [shortcutInfo objectForKey:constKeyModifierFlags] ;
504506
if ([number respondsToSelector:@selector(unsignedIntegerValue)]) {
505507
keyCombo.flags = [number unsignedIntegerValue] ;
506508
}
507-
else {
508-
keyCombo.flags = 0 ;
509-
}
510-
}
511-
else {
512-
keyCombo.code = -1 ;
513-
keyCombo.flags = 0 ;
514509
}
515510
}
516511

0 commit comments

Comments
 (0)