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

View File

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

View File

@@ -61,9 +61,11 @@
- (id)init
{
[super init];
m_isUnderline = false;
m_isStrikethrough = false;
if (self = [super init])
{
m_isUnderline = false;
m_isStrikethrough = false;
}
return self;
}
@@ -118,37 +120,38 @@
@implementation wxMacFontPanelAccView : NSView
- (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() );
wxCFStringRef cfCancelString( wxT("Cancel"), wxLocale::GetSystemEncoding() );
NSRect rectCancel = NSMakeRect( (CGFloat) 10.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 );
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 );
NSRect rectOK = NSMakeRect( (CGFloat)100.0 , (CGFloat)10.0 , (CGFloat)82 , (CGFloat)24 );
NSButton* cancelButton = [[NSButton alloc] initWithFrame:rectCancel];
[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];
[cancelButton setTitle:(NSString*)wxCFRetain((CFStringRef)cfCancelString)];
[cancelButton setBezelStyle:NSRoundedBezelStyle];
[cancelButton setButtonType:NSMomentaryPushInButton];
[cancelButton setAction:@selector(cancelPressed:)];
[cancelButton setTarget:self];
m_cancelButton = cancelButton ;
NSButton* okButton = [[NSButton alloc] initWithFrame:rectOK];
[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 ;
NSButton* okButton = [[NSButton alloc] initWithFrame:rectOK];
[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:okButton];
[self addSubview:cancelButton];
[self addSubview:okButton];
[self resetFlags];
[self resetFlags];
}
return self;
}
@@ -318,8 +321,10 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog);
- (id)init
{
[super init];
m_bIsClosed = false;
if ( self = [super init] )
{
m_bIsClosed = false;
}
return self;
}
@@ -362,10 +367,11 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxFontDialog, wxDialog);
- (id)init
{
[super init];
m_bIsClosed = false;
m_bIsOpen = false;
if ( self = [super init] )
{
m_bIsClosed = false;
m_bIsOpen = false;
}
return self;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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