Correct issues with missing or incorrect self

tests in initXXX methods pointed out by static analyser.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@32588 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2011-03-14 22:59:20 +00:00
parent 412547c233
commit 2e738f7ba2
23 changed files with 204 additions and 50 deletions

View file

@ -1,3 +1,29 @@
2011-03-14 Fred Kiefer <FredKiefer@gmx.de>
* ColorPickers/GSNamedColorPicker.m
* Source/NSBrowser.m
* Source/NSPanel.m
* Source/NSOpenPanel.m
* Source/GSDisplayServer.m
* Source/NSFormCell.m
* Source/NSBitmapImageRep.m
* Source/NSForm.m
* Source/GSVbox.m
* Source/NSSavePanel.m
* Source/GSMemoryPanel.m
* Source/NSScroller.m
* Source/NSMenuView.m
* Source/NSSecureTextField.m
* Source/NSHelpPanel.m
* Source/NSSegmentedCell.m
* Source/NSStepperCell.m
* Source/NSColorPanel.m
* Source/NSDataLinkPanel.m
* Source/GSTable.m
* Source/NSBrowserCell.m
* Source/GSHbox.m: Correct issues with missing or incorrect self
tests in initXXX methods pointed out by static analyser.
2011-03-14 Fred Kiefer <FredKiefer@gmx.de>
* Printing/GSCUPS/GSCUPSPrinter.m (+printerWithName:) Autorelease

View file

@ -49,9 +49,13 @@
{
if (aMask & NSColorPanelColorListModeMask)
{
lists = [[NSColorList availableColorLists] mutableCopy];
return [super initWithPickerMask: aMask
self = [super initWithPickerMask: aMask
colorPanel: colorPanel];
if (nil == self)
return nil;
lists = [[NSColorList availableColorLists] mutableCopy];
return self;
}
RELEASE(self);
return nil;

View file

@ -213,7 +213,9 @@ GSCurrentServer(void)
*/
- (id) initWithAttributes: (NSDictionary *)attributes
{
[super init];
self = [super init];
if (nil == self)
return nil;
server_info = [attributes mutableCopy];
event_queue = [[NSMutableArray allocWithZone: [self zone]]

View file

@ -39,21 +39,27 @@
if (self == [GSHbox class])
[self setVersion: 1];
}
//
// Instance Methods
//
-(id) init
{
[super initWithNumberOfRows: 1
numberOfColumns: 1];
self = [super initWithNumberOfRows: 1
numberOfColumns: 1];
if (nil == self)
return nil;
_haveViews = NO;
_defaultMinXMargin = 0;
return self;
}
-(void) dealloc
{
[super dealloc];
}
//
// Adding Views
//
@ -63,6 +69,7 @@
enablingXResizing: YES
withMinXMargin: _defaultMinXMargin];
}
-(void) addView: (NSView *)aView
enablingXResizing: (BOOL)aFlag
{
@ -70,6 +77,7 @@ enablingXResizing: (BOOL)aFlag
enablingXResizing: aFlag
withMinXMargin: _defaultMinXMargin];
}
-(void) addView: (NSView *)aView
withMinXMargin: (float) aMargin
{
@ -77,6 +85,7 @@ enablingXResizing: (BOOL)aFlag
enablingXResizing: YES
withMinXMargin: aMargin];
}
-(void) addView: (NSView *)aView
enablingXResizing: (BOOL)aFlag
withMinXMargin: (float)aMargin
@ -115,6 +124,7 @@ enablingXResizing: (BOOL)aFlag
}
}
//
// Adding a Separator
//
@ -122,6 +132,7 @@ enablingXResizing: (BOOL)aFlag
{
[self addSeparatorWithMinXMargin: _defaultMinXMargin];
}
-(void) addSeparatorWithMinXMargin: (float)aMargin
{
NSBox *separator;
@ -136,6 +147,7 @@ enablingXResizing: (BOOL)aFlag
withMinXMargin: aMargin];
[separator release];
}
//
// Setting Margins
//
@ -175,7 +187,10 @@ enablingXResizing: (BOOL)aFlag
-(id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
_haveViews = [aDecoder decodeBoolForKey: @"GSHaveViews"];

View file

@ -193,8 +193,6 @@ static GSMemoryPanel *sharedGSMemoryPanel = nil;
/* Activate debugging of allocation. */
GSDebugAllocationActive (YES);
orderingBy = @selector(compareByCount:);
array = [NSMutableArray new];
hbox = [GSHbox new];
[hbox setDefaultMinXMargin: 5];
[hbox setBorder: 5];
@ -266,13 +264,12 @@ static GSMemoryPanel *sharedGSMemoryPanel = nil;
scrollView = [[NSScrollView alloc]
initWithFrame: NSMakeRect (0, 0, 350, 300)];
[scrollView setDocumentView: table];
RELEASE (table);
[scrollView setHasHorizontalScroller: YES];
[scrollView setHasVerticalScroller: YES];
[scrollView setBorderType: NSBezelBorder];
[scrollView setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
[table sizeToFit];
RELEASE (table);
vbox = [GSVbox new];
[vbox setDefaultMinYMargin: 5];
@ -287,13 +284,18 @@ static GSMemoryPanel *sharedGSMemoryPanel = nil;
winFrame.origin = NSMakePoint (100, 200);
self = [super initWithContentRect: winFrame
styleMask: (NSTitledWindowMask
| NSClosableWindowMask
| NSMiniaturizableWindowMask
| NSResizableWindowMask)
backing: NSBackingStoreBuffered
defer: NO];
styleMask: (NSTitledWindowMask
| NSClosableWindowMask
| NSMiniaturizableWindowMask
| NSResizableWindowMask)
backing: NSBackingStoreBuffered
defer: NO];
if (nil == self)
return nil;
array = [NSMutableArray new];
orderingBy = @selector(compareByCount:);
[self setReleasedWhenClosed: NO];
[self setContentView: vbox];
RELEASE (vbox);

View file

@ -65,7 +65,10 @@
{
int i;
[super init];
self = [super init];
if (nil == self)
return nil;
[super setAutoresizesSubviews: NO];
if (!(rows > 0))
{
@ -134,11 +137,13 @@
return self;
}
-(id) init
{
return [self initWithNumberOfRows: 2
numberOfColumns: 2];
}
-(void) dealloc
{
NSZoneFree (NSDefaultMallocZone (), _jails);
@ -153,11 +158,13 @@
NSZoneFree (NSDefaultMallocZone (), _havePrisoner);
[super dealloc];
}
- (void) setAutoresizesSubviews: (BOOL)flag
{
NSLog (@"Warning: attempt to setAutoresizesSubviews for a GSTable!\n");
return;
}
//
// Setting Border.
//
@ -169,16 +176,19 @@
[self setMaxYBorder: aBorder];
}
-(void) setXBorder: (float)aBorder
{
[self setMinXBorder: aBorder];
[self setMaxXBorder: aBorder];
}
-(void) setYBorder: (float)aBorder
{
[self setMinYBorder: aBorder];
[self setMaxYBorder: aBorder];
}
-(void) setMinXBorder: (float)aBorder
{
float borderChange;
@ -202,6 +212,7 @@
_minXBorder = aBorder;
}
-(void) setMaxXBorder: (float)aBorder
{
float borderChange;
@ -242,6 +253,7 @@
_minYBorder = aBorder;
}
-(void) setMaxYBorder: (float)aBorder
{
float borderChange;
@ -258,6 +270,7 @@
_maxYBorder = aBorder;
}
//
// Adding Views
//
@ -273,6 +286,7 @@
minYMargin: 0
maxYMargin: 0];
}
-(void) putView: (NSView *)aView
atRow: (int)row
column: (int)column
@ -286,6 +300,7 @@
minYMargin: margins
maxYMargin: margins];
}
-(void) putView: (NSView *)aView
atRow: (int)row
column: (int)column
@ -300,6 +315,7 @@
minYMargin: yMargins
maxYMargin: yMargins];
}
// The other methods are only wrappers for this one.
-(void) putView: (NSView *)aView
atRow: (int)row
@ -496,6 +512,7 @@
{
return _minimumSize;
}
//
// Resizing
//
@ -529,6 +546,7 @@
[self _updateWholeTable];
[super setFrameSize: _minimumSize];
}
//
// Adding Rows and Columns
// These should be used to add more rows and columns to the GSTable.
@ -574,6 +592,7 @@
_minRowDimension[_numberOfRows - 1] = 0;
}
// TODO: -(void) insertRow: (int)row;
// TODO: -(void) removeRow: (int)row;
-(void) addColumn
@ -652,6 +671,7 @@
_expandColumn[aColumn] = aFlag;
}
}
-(BOOL) isXResizingEnabledForColumn: (int)aColumn
{
if (aColumn > (_numberOfColumns - 1))
@ -666,6 +686,7 @@
}
return _expandColumn[aColumn];
}
-(void) setYResizingEnabled: (BOOL)aFlag
forRow: (int)aRow
{
@ -690,6 +711,7 @@
_expandRow[aRow] = aFlag;
}
}
-(BOOL) isYResizingEnabledForRow: (int)aRow
{
if (aRow > (_numberOfRows - 1))
@ -704,6 +726,7 @@
}
return _expandRow[aRow];
}
//
// Getting Row and Column Number
//
@ -711,10 +734,12 @@
{
return _numberOfRows;
}
-(int) numberOfColumns
{
return _numberOfColumns;
}
//
// NSCoding protocol
//
@ -790,7 +815,10 @@
{
int i;
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return self;
[super setAutoresizesSubviews: NO];
if ([aDecoder allowsKeyedCoding])
@ -1066,7 +1094,6 @@
}
}
//
// After computing new theoretical sizes/positions,
// use the following methods to update the real table view
@ -1089,6 +1116,7 @@
}
}
}
-(void) _updateColumnSize: (int)column
{
int i;
@ -1103,6 +1131,7 @@
}
}
}
-(void) _updateRowOrigin: (int)row
{
int i;
@ -1118,6 +1147,7 @@
}
}
}
-(void) _updateColumnOrigin: (int)column
{
int i;
@ -1132,6 +1162,7 @@
}
}
}
-(void) _updateWholeTable
{
int i,j;
@ -1153,4 +1184,3 @@
@end

View file

@ -40,21 +40,27 @@
if (self == [GSVbox class])
[self setVersion: 1];
}
//
// Instance Methods
//
-(id) init
{
[super initWithNumberOfRows: 1
numberOfColumns: 1];
self = [super initWithNumberOfRows: 1
numberOfColumns: 1];
if (nil == self)
return nil;
_haveViews = NO;
_defaultMinYMargin = 0;
return self;
}
-(void) dealloc
{
[super dealloc];
}
//
// Adding Views
//
@ -64,6 +70,7 @@
enablingYResizing: YES
withMinYMargin: _defaultMinYMargin];
}
-(void) addView: (NSView *)aView
enablingYResizing: (BOOL)aFlag
{
@ -71,6 +78,7 @@ enablingYResizing: (BOOL)aFlag
enablingYResizing: aFlag
withMinYMargin: _defaultMinYMargin];
}
-(void) addView: (NSView *)aView
withMinYMargin: (float) aMargin
{
@ -78,6 +86,7 @@ enablingYResizing: (BOOL)aFlag
enablingYResizing: YES
withMinYMargin: aMargin];
}
-(void) addView: (NSView *)aView
enablingYResizing: (BOOL)aFlag
withMinYMargin: (float)aMargin
@ -116,6 +125,7 @@ enablingYResizing: (BOOL)aFlag
}
}
//
// Adding a Separator
//
@ -123,6 +133,7 @@ enablingYResizing: (BOOL)aFlag
{
[self addSeparatorWithMinYMargin: _defaultMinYMargin];
}
-(void) addSeparatorWithMinYMargin: (float)aMargin
{
NSBox *separator;
@ -177,7 +188,10 @@ enablingYResizing: (BOOL)aFlag
-(id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
_haveViews = [aDecoder decodeBoolForKey: @"GSHaveViews"];

View file

@ -618,12 +618,12 @@
- (int) incrementalLoadFromData: (NSData *)data complete: (BOOL)complete
{
if (!complete)
if (!complete)
{
// we don't implement it really
return NSImageRepLoadStatusWillNeedAllData;
}
return [self initWithData:data] ? NSImageRepLoadStatusCompleted : NSImageRepLoadStatusUnexpectedEOF;
return [self initWithData:data] ? NSImageRepLoadStatusCompleted : NSImageRepLoadStatusUnexpectedEOF;
}
- (void) dealloc

View file

@ -95,7 +95,9 @@ static NSTextFieldCell *titleCell;
- (id) init
{
[super init];
self = [super init];
if (nil == self)
return nil;
_isLoaded = NO;
@ -174,7 +176,6 @@ static NSTextFieldCell *titleCell;
{
if ([aDecoder allowsKeyedCoding])
{
}
else
{

View file

@ -106,7 +106,10 @@ static NSFont *_leafFont;
*/
- (id) initTextCell: (NSString *)aString
{
[super initTextCell: aString];
self = [super initTextCell: aString];
if (nil == self)
return self;
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
@ -120,7 +123,10 @@ static NSFont *_leafFont;
- (id) initImageCell: (NSImage *)anImage
{
[super initImageCell: anImage];
self = [super initImageCell: anImage];
if (nil == self)
return self;
//_alternateImage = nil;
//_browsercell_is_leaf = NO;
//_browsercell_is_loaded = NO;
@ -357,7 +363,9 @@ static NSFont *_leafFont;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return self;
if ([aDecoder allowsKeyedCoding])
{

View file

@ -231,6 +231,9 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
backing: NSBackingStoreRetained
defer: NO
screen: nil];
if (nil == self)
return nil;
[self setTitle: _(@"Colors")];
[self setBecomesKeyOnlyIfNeeded: YES];
[self setContentMinSize: contentRect.size];
@ -710,7 +713,9 @@ static int _gs_gui_color_picker_mode = NSRGBModeColorPanel;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
return self;
}

View file

@ -255,7 +255,9 @@ static NSDataLinkPanel *_sharedDataLinkPanel;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
return self;
}

View file

@ -69,6 +69,8 @@ static Class defaultCellClass = nil;
cellClass: (Class)class
numberOfRows: (int)rowsHigh
numberOfColumns: (int)colsWide];
if (nil == self)
return nil;
[self setIntercellSpacing: NSMakeSize (0, 4)];
return self;
@ -85,6 +87,8 @@ static Class defaultCellClass = nil;
prototype: (NSCell*)prototype
numberOfRows: (int)rowsHigh
numberOfColumns: (int)colsWide];
if (nil == self)
return nil;
[self setIntercellSpacing: NSMakeSize (0, 4)];
return self;
@ -413,7 +417,9 @@ static Class defaultCellClass = nil;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
return self;
}

View file

@ -61,7 +61,8 @@
*/
- (id) initTextCell: (NSString *)aString
{
if (! ( self = [super initTextCell: @""] ) )
self = [super initTextCell: @""];
if (nil == self)
return nil;
_cell.is_bezeled = YES;
@ -473,7 +474,10 @@
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
if ([aDecoder containsValueForKey: @"NSContents"])

View file

@ -147,6 +147,9 @@ static NSHelpPanel *_sharedPanel = nil;
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask
backing: NSBackingStoreBuffered
defer: NO];
if (nil == self)
return nil;
[self setReleasedWhenClosed: NO];
[self setTitle: _(@"Help")];
s = [[NSScrollView alloc] initWithFrame: contentRect];
@ -177,6 +180,7 @@ static NSHelpPanel *_sharedPanel = nil;
else
{
RELEASE(self);
RETAIN(_sharedPanel);
}
return _sharedPanel;
}
@ -220,7 +224,9 @@ static NSHelpPanel *_sharedPanel = nil;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
return self;
}

View file

@ -188,8 +188,8 @@ static NSMapTable *viewInfo = 0;
- (id) initAsTearOff
{
[self initWithFrame: NSZeroRect];
if (!self)
self = [self initWithFrame: NSZeroRect];
if (nil == self)
return nil;
if (_attachedMenu)

View file

@ -615,7 +615,9 @@ static NSOpenPanel *_gs_gui_open_panel = nil;
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_canChooseDirectories];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_canChooseFiles];

View file

@ -205,7 +205,10 @@
{
BOOL flag;
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
// Nothing to do here, for keyed coding this is handled by NSWindowTemplate.

View file

@ -196,9 +196,12 @@ setPath(NSBrowser *browser, NSString *path)
// minimum size we want it to have. Then, we resize it at the
// comfortable size of (384, 426).
//
[super initWithContentRect: NSMakeRect (100, 100, 308, 317)
styleMask: (NSTitledWindowMask | NSResizableWindowMask)
backing: 2 defer: YES];
self = [super initWithContentRect: NSMakeRect (100, 100, 308, 317)
styleMask: (NSTitledWindowMask | NSResizableWindowMask)
backing: 2 defer: YES];
if (nil == self)
return nil;
[self setMinSize: [self frame].size];
r = NSMakeRect (0, 0, 308, 317);
@ -709,7 +712,9 @@ selectCellWithString: (NSString*)title
// complicated initializations, you get a simple panel from super.
-(id) init
{
[self _initWithoutGModel];
self = [self _initWithoutGModel];
if (nil == self)
return nil;
/*
* All these are set automatically
@ -1473,6 +1478,8 @@ selectCellWithString: (NSString*)title
- (id) initWithCoder: (NSCoder*)aDecoder
{
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
// TODO
return self;

View file

@ -236,6 +236,8 @@ static float buttonsOffset = 1.0; // buttonsWidth = sw - 2*buttonsOffset
- (id) initWithCoder: (NSCoder*)aDecoder
{
self = [super initWithCoder: aDecoder];
if(nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{
@ -352,17 +354,19 @@ static float buttonsOffset = 1.0; // buttonsWidth = sw - 2*buttonsOffset
- (id) initWithFrame: (NSRect)frameRect
{
BOOL isHorizontal;
/*
* determine the orientation of the scroller and adjust it's size accordingly
*/
if (frameRect.size.width > frameRect.size.height)
{
_scFlags.isHorizontal = YES;
isHorizontal = YES;
frameRect.size.height = [[self class] scrollerWidth];
}
else
{
_scFlags.isHorizontal = NO;
isHorizontal = NO;
frameRect.size.width = [[self class] scrollerWidth];
}
@ -370,6 +374,7 @@ static float buttonsOffset = 1.0; // buttonsWidth = sw - 2*buttonsOffset
if (!self)
return nil;
_scFlags.isHorizontal = isHorizontal;
if (_scFlags.isHorizontal)
{
_arrowsPosition = NSScrollerArrowsMinEnd;

View file

@ -97,6 +97,9 @@
- (id) initWithFrame:(NSRect)frameRect
{
self = [super initWithFrame: frameRect];
if (nil == self)
return nil;
[self setEchosBullets: YES];
return self;
@ -216,6 +219,9 @@
- (id) initWithCoder: (NSCoder *)decoder
{
self = [super initWithCoder: decoder];
if (nil == self)
return nil;
if ([decoder allowsKeyedCoding])
{
_echosBullets = [decoder decodeBoolForKey: @"GSEchoBullets"];
@ -298,7 +304,9 @@
GSSimpleSecureLayoutManager *m;
/* Perform the normal init. */
[super initWithFrame: frameRect textContainer: aTextContainer];
self = [super initWithFrame: frameRect textContainer: aTextContainer];
if (nil == self)
return nil;
/* Then, replace the layout manager with a
* GSSimpleSecureLayoutManager. */

View file

@ -74,7 +74,9 @@
- (id) init
{
self = [super init];
if (nil == self)
return nil;
_enabled = YES;
return self;

View file

@ -365,7 +365,9 @@
- (id) initWithCoder: (NSCoder*)aDecoder
{
[super initWithCoder: aDecoder];
self = [super initWithCoder: aDecoder];
if (nil == self)
return nil;
if ([aDecoder allowsKeyedCoding])
{