analyzer warnings: assign [super init] to self and check for nil

This commit is contained in:
Stefan Csomor
2017-06-07 10:21:18 +02:00
parent c6ca6d922f
commit 4312de64c7
15 changed files with 165 additions and 121 deletions

View File

@@ -460,8 +460,10 @@ void wxWebKitCtrl::MacVisibilityChanged(){
- (id)initWithWxWindow: (wxWebKitCtrl*)inWindow - (id)initWithWxWindow: (wxWebKitCtrl*)inWindow
{ {
self = [super init]; if ( self = [super init] )
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }
@@ -541,8 +543,10 @@ void wxWebKitCtrl::MacVisibilityChanged(){
- (id)initWithWxWindow: (wxWebKitCtrl*)inWindow - (id)initWithWxWindow: (wxWebKitCtrl*)inWindow
{ {
self = [super init]; if ( self = [super init] )
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }
@@ -592,8 +596,10 @@ void wxWebKitCtrl::MacVisibilityChanged(){
- (id)initWithWxWindow: (wxWebKitCtrl*)inWindow - (id)initWithWxWindow: (wxWebKitCtrl*)inWindow
{ {
self = [super init]; if ( self = [super init] )
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }

View File

@@ -56,9 +56,10 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog);
- (id)init - (id)init
{ {
self = [super init]; if ( self = [super init] )
m_bIsClosed = false; {
m_bIsClosed = false;
}
return self; return self;
} }

View File

@@ -61,9 +61,11 @@
- (id)init - (id)init
{ {
[super init]; if (self = [super init])
m_isUnderline = false; {
m_isStrikethrough = false; m_isUnderline = false;
m_isStrikethrough = false;
}
return self; return self;
} }
@@ -118,37 +120,38 @@
@implementation wxMacFontPanelAccView : NSView @implementation wxMacFontPanelAccView : NSView
- (id)initWithFrame:(NSRect)rectBox - (id)initWithFrame:(NSRect)rectBox
{ {
[super initWithFrame:rectBox]; if ( self = [super initWithFrame:rectBox] )
{
wxCFStringRef cfOkString( wxT("OK"), wxLocale::GetSystemEncoding() );
wxCFStringRef cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() );
wxCFStringRef cfOkString( wxT("OK"), wxLocale::GetSystemEncoding() ); NSRect rectCancel = NSMakeRect( (CGFloat) 10.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 );
wxCFStringRef cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() ); NSRect rectOK = NSMakeRect( (CGFloat)100.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 );
NSRect rectCancel = NSMakeRect( (CGFloat) 10.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 ); NSButton* cancelButton = [[NSButton alloc] initWithFrame:rectCancel];
NSRect rectOK = NSMakeRect( (CGFloat)100.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 ); [cancelButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfCancelString)];
[cancelButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setButtonType:NSMomentaryPushInButton];
[cancelButton setAction:@selector(cancelPressed:)];
[cancelButton setTarget:self];
m_cancelButton = cancelButton ;
NSButton* cancelButton = [[NSButton alloc] initWithFrame:rectCancel]; NSButton* okButton = [[NSButton alloc] initWithFrame:rectOK];
[cancelButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfCancelString)]; [okButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfOkString)];
[cancelButton setBezelStyle:NSRoundedBezelStyle]; [okButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setButtonType:NSMomentaryPushInButton]; [okButton setButtonType:NSMomentaryPushInButton];
[cancelButton setAction:@selector(cancelPressed:)]; [okButton setAction:@selector(okPressed:)];
[cancelButton setTarget:self]; [okButton setTarget:self];
m_cancelButton = cancelButton ; // doesn't help either, the button is not highlighted after a color dialog has been used
// [okButton setKeyEquivalent:@"\r"];
NSButton* okButton = [[NSButton alloc] initWithFrame:rectOK]; m_okButton = okButton ;
[okButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfOkString)];
[okButton setBezelStyle:NSRoundedBezelStyle];
[okButton setButtonType:NSMomentaryPushInButton];
[okButton setAction:@selector(okPressed:)];
[okButton setTarget:self];
// doesn't help either, the button is not highlighted after a color dialog has been used
// [okButton setKeyEquivalent:@"\r"];
m_okButton = okButton ;
[self addSubview:cancelButton]; [self addSubview:cancelButton];
[self addSubview:okButton]; [self addSubview:okButton];
[self resetFlags]; [self resetFlags];
}
return self; return self;
} }
@@ -318,9 +321,11 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog);
- (id)init - (id)init
{ {
[super init]; if ( self = [super init] )
m_bIsClosed = false; {
m_bIsClosed = false;
}
return self; return self;
} }
@@ -362,10 +367,11 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog);
- (id)init - (id)init
{ {
[super init]; if ( self = [super init] )
m_bIsClosed = false; {
m_bIsOpen = false; m_bIsClosed = false;
m_bIsOpen = false;
}
return self; return self;
} }

View File

@@ -196,7 +196,7 @@ inline wxDataViewItem wxDataViewItemFromMaybeNilItem(id item)
-(id) initWithColumnPointer:(const wxDataViewColumn*)column -(id) initWithColumnPointer:(const wxDataViewColumn*)column
{ {
[self initWithIdentifier: [wxDVCNSTableColumn identifierForColumnPointer:column]]; self = [self initWithIdentifier: [wxDVCNSTableColumn identifierForColumnPointer:column]];
return self; return self;
} }

View File

@@ -73,11 +73,13 @@ wxDragResult NSDragOperationToWxDragResult(NSDragOperation code)
- (id)init - (id)init
{ {
self = [super init]; if ( self = [super init] )
dragFinished = NO; {
resultCode = NSDragOperationNone; dragFinished = NO;
impl = 0; resultCode = NSDragOperationNone;
m_dragFlags = wxDrag_CopyOnly; impl = 0;
m_dragFlags = wxDrag_CopyOnly;
}
return self; return self;
} }

View File

@@ -68,8 +68,10 @@
- (id) init - (id) init
{ {
self = [super init]; if ( self = [super init] )
_dialog = NULL; {
_dialog = NULL;
}
return self; return self;
} }

View File

@@ -160,8 +160,10 @@ protected :
- (id) init - (id) init
{ {
self = [super init]; if ( self = [super init] )
column = nil; {
column = nil;
}
return self; return self;
} }
@@ -223,8 +225,10 @@ protected:
- (id) init - (id) init
{ {
self = [super init]; if ( self = [super init] )
impl = nil; {
impl = nil;
}
return self; return self;
} }

View File

@@ -134,13 +134,13 @@ private:
- (id) init - (id) init
{ {
self = [super init]; if ( self = [super init] )
{
[self addObserver:self forKeyPath:@"currentItem.status" [self addObserver:self forKeyPath:@"currentItem.status"
options:NSKeyValueObservingOptionNew context:AVSPPlayerItemStatusContext]; options:NSKeyValueObservingOptionNew context:AVSPPlayerItemStatusContext];
[self addObserver:self forKeyPath:@"rate" [self addObserver:self forKeyPath:@"rate"
options:NSKeyValueObservingOptionNew context:AVSPPlayerRateContext]; options:NSKeyValueObservingOptionNew context:AVSPPlayerRateContext];
}
return self; return self;
} }
@@ -257,13 +257,12 @@ private:
- (id) initWithFrame:(CGRect)rect player:(wxAVPlayer*) player - (id) initWithFrame:(CGRect)rect player:(wxAVPlayer*) player
{ {
if ( !(self=[super initWithFrame:rect]) ) if ( self = [super initWithFrame:rect] )
return nil; {
AVPlayerLayer* playerLayer = (AVPlayerLayer*) [self layer];
AVPlayerLayer* playerLayer = (AVPlayerLayer*) [self layer]; [playerLayer setPlayer: player];
[playerLayer setPlayer: player]; [player setPlayerLayer:playerLayer];
[player setPlayerLayer:playerLayer]; }
return self; return self;
} }
@@ -297,11 +296,10 @@ private:
- (id) initWithFrame:(NSRect)rect player:(wxAVPlayer*) player - (id) initWithFrame:(NSRect)rect player:(wxAVPlayer*) player
{ {
if ( !(self=[super initWithFrame:rect]) ) if ( self = [super initWithFrame:rect] )
return nil; {
self.player = player;
self.player = player; }
return self; return self;
} }
@@ -334,17 +332,17 @@ private:
- (id) initWithFrame:(NSRect)rect player:(wxAVPlayer*) player - (id) initWithFrame:(NSRect)rect player:(wxAVPlayer*) player
{ {
if ( !(self=[super initWithFrame:rect]) ) if ( self = [super initWithFrame:rect] )
return nil; {
[self setWantsLayer:YES];
AVPlayerLayer* playerlayer = [[AVPlayerLayer playerLayerWithPlayer: player] retain];
[player setPlayerLayer:playerlayer];
[playerlayer setFrame:[[self layer] bounds]];
[playerlayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
[[self layer] addSublayer:playerlayer];
}
[self setWantsLayer:YES];
AVPlayerLayer* playerlayer = [[AVPlayerLayer playerLayerWithPlayer: player] retain];
[player setPlayerLayer:playerlayer];
[playerlayer setFrame:[[self layer] bounds]];
[playerlayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable];
[[self layer] addSublayer:playerlayer];
return self; return self;
} }

View File

@@ -37,8 +37,10 @@
- (id) initWithTitle:(NSString*) title - (id) initWithTitle:(NSString*) title
{ {
self = [super initWithTitle:title]; if ( self = [super initWithTitle:title] )
impl = NULL; {
impl = NULL;
}
return self; return self;
} }

View File

@@ -112,8 +112,11 @@
@implementation WXCTabViewImageItem : NSTabViewItem @implementation WXCTabViewImageItem : NSTabViewItem
- (id)init - (id)init
{ {
m_image = nil; if (self = [super initWithIdentifier:nil])
return [super initWithIdentifier:nil]; {
m_image = nil;
}
return self;
} }
- (void)dealloc - (void)dealloc
{ {

View File

@@ -130,9 +130,11 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
- (id)init - (id)init
{ {
self = [super init]; if ( self = [super init] )
maxLength = 0; {
forceUpper = false; maxLength = 0;
forceUpper = false;
}
return self; return self;
} }
@@ -495,8 +497,10 @@ NSView* wxMacEditHelper::ms_viewCurrentlyEdited = nil;
- (id) initWithFrame:(NSRect) frame - (id) initWithFrame:(NSRect) frame
{ {
self = [super initWithFrame:frame]; if ( self = [super initWithFrame:frame] )
fieldEditor = nil; {
fieldEditor = nil;
}
return self; return self;
} }

View File

@@ -368,10 +368,12 @@ private:
- (id)initWithItemIdentifier: (NSString*) identifier - (id)initWithItemIdentifier: (NSString*) identifier
{ {
self = [super initWithItemIdentifier:identifier]; if ( self = [super initWithItemIdentifier:identifier] )
impl = NULL; {
[self setTarget: self]; impl = NULL;
[self setAction: @selector(clickedAction:)]; [self setTarget: self];
[self setAction: @selector(clickedAction:)];
}
return self; return self;
} }
@@ -406,8 +408,11 @@ private:
- (id)init - (id)init
{ {
m_isSelectable = false; if ( self = [super init] )
return [super init]; {
m_isSelectable = false;
}
return self;
} }
- (void)setSelectable:(bool) value - (void)setSelectable:(bool) value
@@ -469,8 +474,7 @@ private:
- (id)initWithIdentifier:(NSString *)identifier - (id)initWithIdentifier:(NSString *)identifier
{ {
self = [super initWithIdentifier:identifier]; if (self = [super initWithIdentifier:identifier])
if (self)
{ {
toolbarDelegate = [[wxNSToolbarDelegate alloc] init]; toolbarDelegate = [[wxNSToolbarDelegate alloc] init];
[self setDelegate:toolbarDelegate]; [self setDelegate:toolbarDelegate];
@@ -492,10 +496,12 @@ private:
- (id)initWithFrame:(NSRect)frame - (id)initWithFrame:(NSRect)frame
{ {
self = [super initWithFrame:frame]; if ( self = [super initWithFrame:frame] )
impl = NULL; {
[self setTarget: self]; impl = NULL;
[self setAction: @selector(clickedAction:)]; [self setTarget: self];
[self setAction: @selector(clickedAction:)];
}
return self; return self;
} }

View File

@@ -232,10 +232,12 @@ void wxBell()
@implementation ModalDialogDelegate @implementation ModalDialogDelegate
- (id)init - (id)init
{ {
self = [super init]; if ( self = [super init] )
sheetFinished = NO; {
resultCode = -1; sheetFinished = NO;
impl = 0; resultCode = -1;
impl = 0;
}
return self; return self;
} }
@@ -336,8 +338,10 @@ void wxBell()
- (id)init - (id)init
{ {
self = [super init]; if ( self = [super init] )
firstPass = YES; {
firstPass = YES;
}
return self; return self;
} }

View File

@@ -1916,11 +1916,11 @@ double wxWidgetCocoaImpl::GetContentScaleFactor() const
- (id)init:(wxWindow *)win - (id)init:(wxWindow *)win
{ {
self = [super init]; if ( self = [super init] )
{
m_win = win; m_win = win;
m_isDone = false; m_isDone = false;
}
return self; return self;
} }

View File

@@ -690,8 +690,10 @@ void wxWebViewWebKit::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
- (id)initWithWxWindow: (wxWebViewWebKit*)inWindow - (id)initWithWxWindow: (wxWebViewWebKit*)inWindow
{ {
[super init]; if (self = [super init])
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }
@@ -878,8 +880,10 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
- (id)initWithWxWindow: (wxWebViewWebKit*)inWindow - (id)initWithWxWindow: (wxWebViewWebKit*)inWindow
{ {
[super init]; if (self = [super init])
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }
@@ -1036,8 +1040,10 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out)
- (id)initWithWxWindow: (wxWebViewWebKit*)inWindow - (id)initWithWxWindow: (wxWebViewWebKit*)inWindow
{ {
[super init]; if (self = [super init])
webKitWindow = inWindow; // non retained {
webKitWindow = inWindow; // non retained
}
return self; return self;
} }