From 694227fe64cc12c3a0577895fcf394e79731c77b Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:36:04 +0200 Subject: [PATCH 01/11] Fixes analyzer issue: Instance variable used while 'self' is not set matrixManager is assigned before self is set to [self init..] or [super init..] Moved assignment to after self = [super init...] --- src/Cocoa/MyOpenGLView.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Cocoa/MyOpenGLView.m b/src/Cocoa/MyOpenGLView.m index 9102fd2d8..0680c7f60 100644 --- a/src/Cocoa/MyOpenGLView.m +++ b/src/Cocoa/MyOpenGLView.m @@ -87,8 +87,6 @@ - (id) initWithFrame:(NSRect)frameRect } #endif - matrixManager = [[OOOpenGLMatrixManager alloc] init]; - // Pixel Format Attributes for the View-based (non-FullScreen) NSOpenGLContext NSOpenGLPixelFormatAttribute attrs[] = { @@ -137,6 +135,7 @@ - (id) initWithFrame:(NSRect)frameRect [self setWantsBestResolutionOpenGLSurface:YES]; } + matrixManager = [[OOOpenGLMatrixManager alloc] init]; _pixelFormatAttributes = [[NSData alloc] initWithBytes:attrs length:sizeof attrs]; virtualJoystickPosition = NSMakePoint(0.0,0.0); From da2f747b03393d69c4524a5f6ca53d35a6dc9a5e Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:36:20 +0200 Subject: [PATCH 02/11] Fixes analyzer issue: initial value never used targetName is declared and assigned a vale. Its first use is another assignment. Moved declaration to first assignment that gets used. --- src/Core/GuiDisplayGen.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Core/GuiDisplayGen.m b/src/Core/GuiDisplayGen.m index 306e307cc..32331f572 100644 --- a/src/Core/GuiDisplayGen.m +++ b/src/Core/GuiDisplayGen.m @@ -1782,7 +1782,6 @@ - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha :(BOO (textRow-1) * MAIN_GUI_ROW_HEIGHT * pixelRatio); OOSystemID target = [PLAYER targetSystemID]; - NSString *targetName = [UNIVERSE getSystemName:target]; double dx, dy; // get a list of systems marked as contract destinations @@ -2234,7 +2233,7 @@ - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha :(BOO tab_stops[2] = 288; [self overrideTabs:tab_stops from:kGuiChartTraveltimeTabs length:3]; [self setTabStops:tab_stops]; - targetName = [[UNIVERSE getSystemName:target] retain]; + NSString *targetName = [[UNIVERSE getSystemName:target] retain]; // distance-f & est-travel-time-f are identical between short & long range charts in standard Oolite, however can be alterered separately via OXPs NSString *travelDistLine = @""; From 2bd99d0b24fcdbc66c7b27f6ffe91d57a41855be Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:36:38 +0200 Subject: [PATCH 03/11] Fixes analyzer issue: Initial value never used targetCoordinates is assined a value in its declaration. Its first use is another assignment. Moved declaration to first assignment that gets used. --- src/Core/GuiDisplayGen.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Core/GuiDisplayGen.m b/src/Core/GuiDisplayGen.m index 32331f572..bd7287424 100644 --- a/src/Core/GuiDisplayGen.m +++ b/src/Core/GuiDisplayGen.m @@ -1892,10 +1892,9 @@ - (void) drawStarChart:(GLfloat)x :(GLfloat)y :(GLfloat)z :(GLfloat) alpha :(BOO { [self drawAdvancedNavArrayAtX:x+hoffset y:y+voffset z:z alpha:alpha usingRoute:nil optimizedBy:OPTIMIZED_BY_NONE zoom: zoom]; } - NSPoint targetCoordinates = (NSPoint){0,0}; if (!routeExists) { - targetCoordinates = [systemManager getCoordinatesForSystem:target inGalaxy:galaxy_id]; + NSPoint targetCoordinates = [systemManager getCoordinatesForSystem:target inGalaxy:galaxy_id]; distance = distanceBetweenPlanetPositions(targetCoordinates.x,targetCoordinates.y,galaxy_coordinates.x,galaxy_coordinates.y); if (distance == 0.0) From 9e30fce8a498f7bdb5b46d8a9adc2cac09297675 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:36:53 +0200 Subject: [PATCH 04/11] Fixes analyzer issue: Value stored is never used Assignment at :1347 is redundant Removed this line. Moved declaration to first assignment that gets used. --- src/Core/HeadUpDisplay.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Core/HeadUpDisplay.m b/src/Core/HeadUpDisplay.m index 15b48d81e..93905fc65 100644 --- a/src/Core/HeadUpDisplay.m +++ b/src/Core/HeadUpDisplay.m @@ -1182,8 +1182,6 @@ - (void) drawScanner:(NSDictionary *)info GLfloat scanner_color[4] = { 1.0, 0.0, 0.0, 1.0 }; BOOL emptyDial = ([info oo_floatForKey:ALPHA_KEY] == 0.0f); - - BOOL isHostile = NO; if (emptyDial) { @@ -1344,11 +1342,10 @@ - (void) drawScanner:(NSDictionary *)info y1 = z_factor * relativePosition.z; y2 = y1 + y_factor * relativePosition.y; - isHostile = NO; if ([scannedEntity isShip]) { ShipEntity *ship = (ShipEntity *)scannedEntity; - isHostile = (([ship hasHostileTarget])&&([ship primaryTarget] == PLAYER)); + BOOL isHostile = (([ship hasHostileTarget])&&([ship primaryTarget] == PLAYER)); GLfloat *base_col = [ship scannerDisplayColorForShip:PLAYER :isHostile :flash :[ship scannerDisplayColor1] :[ship scannerDisplayColor2] :[ship scannerDisplayColorHostile1] :[ship scannerDisplayColorHostile2] From e4d3863970bdba601f9d030f5134078ce5e72bd0 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:37:08 +0200 Subject: [PATCH 05/11] Fixes analyzer issue: Value stored is never read Value stored in 'alpha' is never used. Removed variable altogether. Guess at desired behavior: - assign cached alpha to alpha component in textColor, - feed textColor to GetRGBAArrayFromInfo(), which may or may not change it, - multiply result by overallAlpha. --- src/Core/HeadUpDisplay.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Core/HeadUpDisplay.m b/src/Core/HeadUpDisplay.m index 93905fc65..a3541f390 100644 --- a/src/Core/HeadUpDisplay.m +++ b/src/Core/HeadUpDisplay.m @@ -3027,7 +3027,6 @@ - (void) drawWeaponsOfflineText:(NSDictionary *)info { int x, y; NSSize siz; - GLfloat alpha = overallAlpha; struct CachedInfo cached; [(NSValue *)[sCurrentDrawItem objectAtIndex:WIDGET_CACHE] getValue:&cached]; @@ -3036,8 +3035,8 @@ - (void) drawWeaponsOfflineText:(NSDictionary *)info y = useDefined(cached.y, WEAPONSOFFLINETEXT_DISPLAY_Y) + [[UNIVERSE gameView] y_offset] * cached.y0; siz.width = useDefined(cached.width, WEAPONSOFFLINETEXT_WIDTH); siz.height = useDefined(cached.height, WEAPONSOFFLINETEXT_HEIGHT); - alpha *= cached.alpha; + textColor[3] = cached.alpha; GetRGBAArrayFromInfo(info, textColor); textColor[3] *= overallAlpha; From ab59179cb38aa7a1f51f2131609a8b7e7c42b151 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:37:29 +0200 Subject: [PATCH 06/11] Fixes analyzer issue: Access to instance variable results in null pointer dereference If error != NO_ERROR, we release and nillify self, then touch _source. Put subsequent code in else block. --- src/Core/OOALSoundChannel.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Core/OOALSoundChannel.m b/src/Core/OOALSoundChannel.m index e732b8262..38aaeae00 100644 --- a/src/Core/OOALSoundChannel.m +++ b/src/Core/OOALSoundChannel.m @@ -53,9 +53,12 @@ - (id) init [self release]; self = nil; } - // sources are all relative to listener, defaulting to zero vector - OOAL(alSourcei(_source, AL_SOURCE_RELATIVE, AL_TRUE)); - OOAL(alSource3f(_source, AL_POSITION, 0.0f, 0.0f, 0.0f)); + else + { + // sources are all relative to listener, defaulting to zero vector + OOAL(alSourcei(_source, AL_SOURCE_RELATIVE, AL_TRUE)); + OOAL(alSource3f(_source, AL_POSITION, 0.0f, 0.0f, 0.0f)); + } } return self; } From 0122acedf7256016542eba65fbf50e96d7e90f2a Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:37:59 +0200 Subject: [PATCH 07/11] Fixes compiler warning: integer precision 10 warnings in PlayerEntityStickProfile.m Changed some arguments and return values from int to NSUInteger: jostick axis, control index, point count --- src/Core/OOJoystickManager.h | 8 ++++---- src/Core/OOJoystickManager.m | 8 ++++---- src/Core/OOJoystickProfile.h | 4 ++-- src/Core/OOJoystickProfile.m | 4 ++-- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Core/OOJoystickManager.h b/src/Core/OOJoystickManager.h index 530783ed4..86a176e66 100644 --- a/src/Core/OOJoystickManager.h +++ b/src/Core/OOJoystickManager.h @@ -285,10 +285,10 @@ typedef struct - (double) getSensitivity; // Axis profile handling -- (void) setProfile: (OOJoystickAxisProfile *) profile forAxis:(int) axis; -- (OOJoystickAxisProfile *) getProfileForAxis: (int) axis; -- (void) saveProfileForAxis: (int) axis; -- (void) loadProfileForAxis: (int) axis; +- (void) setProfile: (OOJoystickAxisProfile *) profile forAxis:(NSUInteger) axis; +- (OOJoystickAxisProfile *) getProfileForAxis: (NSUInteger) axis; +- (void) saveProfileForAxis: (NSUInteger) axis; +- (void) loadProfileForAxis: (NSUInteger) axis; // This one just returns a pointer to the entire state array to // allow for multiple lookups with only one objc_sendMsg diff --git a/src/Core/OOJoystickManager.m b/src/Core/OOJoystickManager.m index c73be1a5c..dfbefaf19 100644 --- a/src/Core/OOJoystickManager.m +++ b/src/Core/OOJoystickManager.m @@ -164,7 +164,7 @@ - (double) getSensitivity return precisionMode ? STICK_PRECISIONFAC : 1.0; } -- (void) setProfile: (OOJoystickAxisProfile *) profile forAxis: (int) axis +- (void) setProfile: (OOJoystickAxisProfile *) profile forAxis: (NSUInteger) axis { switch (axis) { @@ -186,7 +186,7 @@ - (void) setProfile: (OOJoystickAxisProfile *) profile forAxis: (int) axis return; } -- (OOJoystickAxisProfile *) getProfileForAxis: (int) axis +- (OOJoystickAxisProfile *) getProfileForAxis: (NSUInteger) axis { switch (axis) { @@ -201,7 +201,7 @@ - (OOJoystickAxisProfile *) getProfileForAxis: (int) axis } -- (void) saveProfileForAxis: (int) axis +- (void) saveProfileForAxis: (NSUInteger) axis { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; @@ -260,7 +260,7 @@ - (void) saveProfileForAxis: (int) axis -- (void) loadProfileForAxis: (int) axis +- (void) loadProfileForAxis: (NSUInteger) axis { NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; NSDictionary *dict; diff --git a/src/Core/OOJoystickProfile.h b/src/Core/OOJoystickProfile.h index 19810b924..6a1061c1e 100644 --- a/src/Core/OOJoystickProfile.h +++ b/src/Core/OOJoystickProfile.h @@ -78,9 +78,9 @@ MA 02110-1301, USA. - (id) init; - (void) dealloc; - (id) copyWithZone: (NSZone *) zone; -- (int) addControl: (NSPoint) point; +- (NSInteger) addControl: (NSPoint) point; - (NSPoint) pointAtIndex: (NSInteger) index; -- (int) countPoints; +- (NSInteger) countPoints; - (void) removeControl: (NSInteger) index; - (void) clearControlPoints; - (void) moveControl: (NSInteger) index point: (NSPoint) point; diff --git a/src/Core/OOJoystickProfile.m b/src/Core/OOJoystickProfile.m index e96698a64..f9df8f03e 100644 --- a/src/Core/OOJoystickProfile.m +++ b/src/Core/OOJoystickProfile.m @@ -375,7 +375,7 @@ - (id) copyWithZone: (NSZone *) zone } -- (int) addControl: (NSPoint) point +- (NSInteger) addControl: (NSPoint) point { NSPoint left, right; NSUInteger i; @@ -438,7 +438,7 @@ - (NSPoint) pointAtIndex: (NSInteger) index return point; } -- (int) countPoints +- (NSInteger) countPoints { return [controlPoints count]; } From df5105277f03f359587d20020bf7fd66381c85c0 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:38:13 +0200 Subject: [PATCH 08/11] Fixes compiler warning: integer precision Warning in OOPlanetEntity.m:124 in assignment to _shuttlesOnGround --- src/Core/Entities/OOPlanetEntity.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Core/Entities/OOPlanetEntity.h b/src/Core/Entities/OOPlanetEntity.h index 4c1160ba4..139b6bb07 100644 --- a/src/Core/Entities/OOPlanetEntity.h +++ b/src/Core/Entities/OOPlanetEntity.h @@ -52,7 +52,7 @@ MA 02110-1301, USA. Quaternion _atmosphereOrientation; float _atmosphereRotationalVelocity; - unsigned _shuttlesOnGround; + NSUInteger _shuttlesOnGround; OOTimeDelta _lastLaunchTime; OOTimeDelta _shuttleLaunchInterval; From eb8ad57b1a57b212358d24b2309b6344d46ec367 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:38:27 +0200 Subject: [PATCH 09/11] Fixes compiler warning: integer precision cast activeMFD, NSUInteger, to int32 in call to INT_TO_JSVAL() --- src/Core/Entities/PlayerEntity.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index e734b6b2e..30d6ce5e0 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -5404,7 +5404,7 @@ - (void) cycleMultiFunctionDisplay:(NSUInteger) index } JSContext *context = OOJSAcquireContext(); jsval keyVal = OOJSValueFromNativeObject(context,key); - ShipScriptEvent(context, self, "mfdKeyChanged", INT_TO_JSVAL(activeMFD), keyVal); + ShipScriptEvent(context, self, "mfdKeyChanged", INT_TO_JSVAL((int32)activeMFD), keyVal); OOJSRelinquishContext(context); } @@ -5415,7 +5415,7 @@ - (void) selectNextMultiFunctionDisplay NSUInteger mfdID = activeMFD + 1; [UNIVERSE addMessage:OOExpandKey(@"mfd-N-selected", mfdID) forCount:3.0 ]; JSContext *context = OOJSAcquireContext(); - ShipScriptEvent(context, self, "selectedMFDChanged", INT_TO_JSVAL(activeMFD)); + ShipScriptEvent(context, self, "selectedMFDChanged", INT_TO_JSVAL((int32)activeMFD)); OOJSRelinquishContext(context); } From 9fe960b0af782f24ccad72b9b57932a28767a14d Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:38:40 +0200 Subject: [PATCH 10/11] Fixes compiler warning: integer precision PlayerEntity.m:6918 and :6994 pass OOCreditsQuantity (aka 'unsigned long long') to int Changed markAsOffender prototype to use OOCreditsQuantity for offence_value. --- src/Core/Entities/PlayerEntity.m | 6 +++--- src/Core/Entities/ShipEntity.h | 4 ++-- src/Core/Entities/ShipEntity.m | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 30d6ce5e0..be8f56fe3 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -6558,20 +6558,20 @@ - (int) legalStatus } -- (void) markAsOffender:(int)offence_value +- (void) markAsOffender:(OOCreditsQuantity)offence_value { [self markAsOffender:offence_value withReason:kOOLegalStatusReasonUnknown]; } -- (void) markAsOffender:(int)offence_value withReason:(OOLegalStatusReason)reason +- (void) markAsOffender:(OOCreditsQuantity)offence_value withReason:(OOLegalStatusReason)reason { if (![self isCloaked]) { JSContext *context = OOJSAcquireContext(); jsval amountVal = JSVAL_VOID; - int amountVal2 = (legalStatus | offence_value) - legalStatus; + OOCreditsQuantity amountVal2 = (legalStatus | offence_value) - legalStatus; JS_NewNumberValue(context, amountVal2, &amountVal); legalStatus |= offence_value; // can't set the new bounty until the size of the change is known diff --git a/src/Core/Entities/ShipEntity.h b/src/Core/Entities/ShipEntity.h index cb919eca3..87f153f0b 100644 --- a/src/Core/Entities/ShipEntity.h +++ b/src/Core/Entities/ShipEntity.h @@ -1163,8 +1163,8 @@ Vector positionOffsetForShipInRotationToAlignment(ShipEntity* ship, Quaternion q Mark this ship as an offender, this is different to setBounty as some ships such as police are not markable. The final bounty may not be equal to existing bounty plus offence_value. */ -- (void) markAsOffender:(int)offence_value; -- (void) markAsOffender:(int)offence_value withReason:(OOLegalStatusReason)reason; +- (void) markAsOffender:(OOCreditsQuantity)offence_value; +- (void) markAsOffender:(OOCreditsQuantity)offence_value withReason:(OOLegalStatusReason)reason; - (void) switchLightsOn; - (void) switchLightsOff; diff --git a/src/Core/Entities/ShipEntity.m b/src/Core/Entities/ShipEntity.m index 113ae4d48..0712130a9 100644 --- a/src/Core/Entities/ShipEntity.m +++ b/src/Core/Entities/ShipEntity.m @@ -13564,13 +13564,13 @@ - (BOOL) witchspaceLeavingEffects } -- (void) markAsOffender:(int)offence_value +- (void) markAsOffender:(OOCreditsQuantity)offence_value { [self markAsOffender:offence_value withReason:kOOLegalStatusReasonUnknown]; } -- (void) markAsOffender:(int)offence_value withReason:(OOLegalStatusReason)reason +- (void) markAsOffender:(OOCreditsQuantity)offence_value withReason:(OOLegalStatusReason)reason { if (![self isPolice] && ![self isCloaked] && self != [UNIVERSE station]) { From f80eeb35a5a489609d106837273c7c4454bb9128 Mon Sep 17 00:00:00 2001 From: Job Bolle Date: Sun, 15 Oct 2017 18:38:55 +0200 Subject: [PATCH 11/11] Fixes analyzer issue: Access to instance variable results in null pointer dereference We test for (self == nil) indicating this is a possibility. Then we touch an instance variable regardless. Removed this line. If self == nil, this is a null pointer dereference; if not, standardMatrixUniformLocations is already nil. --- src/Core/Materials/OOShaderProgram.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Core/Materials/OOShaderProgram.m b/src/Core/Materials/OOShaderProgram.m index dfcb602a6..a8da65a45 100644 --- a/src/Core/Materials/OOShaderProgram.m +++ b/src/Core/Materials/OOShaderProgram.m @@ -304,8 +304,6 @@ - (id)initWithVertexShaderSource:(NSString *)vertexSource self = [super init]; if (self == nil) OK = NO; - standardMatrixUniformLocations = nil; - if (OK && vertexSource == nil && fragmentSource == nil) OK = NO; // Must have at least one shader! if (OK && prefixString != nil)