From 8b4c4a8dcf47d60c7f87072b2d78861781820afb Mon Sep 17 00:00:00 2001 From: Aleksey Kononov Date: Fri, 28 Sep 2018 11:16:55 -0700 Subject: [PATCH] Fix warnings found by Xcode analyzer. --- Common/TaskUtil.m | 2 +- Common/XCToolUtil.m | 2 +- .../otest-query.xcodeproj/project.pbxproj | 2 + .../otest-shim.xcodeproj/project.pbxproj | 2 + .../JSONCompilationDatabaseReporter.m | 9 +++-- reporters/junit/JUnitReporter.m | 19 +++++----- reporters/phabricator/PhabricatorReporter.m | 11 +++--- reporters/reporters.xcodeproj/project.pbxproj | 2 + reporters/text/TextReporter.m | 38 ++++++++++--------- .../xcodebuild-shim.xcodeproj/project.pbxproj | 2 + xctool/xctool-tests/FakeTaskManager.m | 11 +++--- xctool/xctool/EventBuffer.m | 9 +++-- xctool/xctool/OCTestEventState.m | 11 +++--- xctool/xctool/SchemeGenerator.m | 8 ++-- .../SimulatorWrapper/SimulatorWrapper.m | 4 +- xctool/xctool/TestRunState.m | 5 ++- 16 files changed, 76 insertions(+), 61 deletions(-) diff --git a/Common/TaskUtil.m b/Common/TaskUtil.m index 794bbb098..184cf176c 100644 --- a/Common/TaskUtil.m +++ b/Common/TaskUtil.m @@ -172,7 +172,7 @@ void ReadOutputsAndFeedOuputLinesToBlockOnQueue( }; size_t (^feedUnprocessedLinesToBlock)(int, dispatch_data_t, BOOL) = ^(int fd, dispatch_data_t unprocessedPart, BOOL forceUntilTheEnd) { - size_t processedSize; + size_t processedSize = 0; NSArray *lines = LinesFromDispatchData(unprocessedPart, YES, forceUntilTheEnd, &processedSize); for (NSString *lineToFeed in lines) { diff --git a/Common/XCToolUtil.m b/Common/XCToolUtil.m index 479471832..bba729722 100644 --- a/Common/XCToolUtil.m +++ b/Common/XCToolUtil.m @@ -228,7 +228,7 @@ const char *template = [[directory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.XXXXXXX", prefix]] UTF8String]; char tempPath[PATH_MAX] = {0}; - strcpy(tempPath, template); + strlcpy(tempPath, template, PATH_MAX); int handle = mkstemp(tempPath); NSCAssert(handle != -1, @"Failed to make temporary file name for template %s, error: %d", template, handle); diff --git a/otest-query/otest-query.xcodeproj/project.pbxproj b/otest-query/otest-query.xcodeproj/project.pbxproj index 07615a0a8..bb13d37b4 100644 --- a/otest-query/otest-query.xcodeproj/project.pbxproj +++ b/otest-query/otest-query.xcodeproj/project.pbxproj @@ -271,7 +271,9 @@ 28660740183471FF000ACB87 /* otest-query-lib */, CD9048FF1756C5B1006CF16D /* Products */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; CD9048FF1756C5B1006CF16D /* Products */ = { isa = PBXGroup; diff --git a/otest-shim/otest-shim.xcodeproj/project.pbxproj b/otest-shim/otest-shim.xcodeproj/project.pbxproj index 21f0f00ec..e98fb1eec 100644 --- a/otest-shim/otest-shim.xcodeproj/project.pbxproj +++ b/otest-shim/otest-shim.xcodeproj/project.pbxproj @@ -168,7 +168,9 @@ 283CCA8E16C2EE4C00F2E343 /* Frameworks */, 283CCA8D16C2EE4C00F2E343 /* Products */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; 283CCA8D16C2EE4C00F2E343 /* Products */ = { isa = PBXGroup; diff --git a/reporters/json-compilation-database/JSONCompilationDatabaseReporter.m b/reporters/json-compilation-database/JSONCompilationDatabaseReporter.m index 86bec7a97..88c2a2b8f 100644 --- a/reporters/json-compilation-database/JSONCompilationDatabaseReporter.m +++ b/reporters/json-compilation-database/JSONCompilationDatabaseReporter.m @@ -51,10 +51,11 @@ - (NSTextCheckingResult *)firstMatch:(NSArray *)prioritizedRegExString @end -@interface JSONCompilationDatabaseReporter () -@property (nonatomic, copy) NSMutableArray *compiles; -@property (nonatomic, copy) NSDictionary *currentBuildCommand; -@property (nonatomic, copy) NSMutableArray *precompiles; +@interface JSONCompilationDatabaseReporter () { + NSMutableArray *_compiles; + NSDictionary *_currentBuildCommand; + NSMutableArray *_precompiles; +} @end @implementation JSONCompilationDatabaseReporter diff --git a/reporters/junit/JUnitReporter.m b/reporters/junit/JUnitReporter.m index 13788dfe8..0a21e29dc 100644 --- a/reporters/junit/JUnitReporter.m +++ b/reporters/junit/JUnitReporter.m @@ -23,16 +23,15 @@ #define kJUnitReporter_Suite_Results @"results" #pragma mark Private Interface -@interface JUnitReporter () - -@property (nonatomic, copy) NSMutableArray *testSuites; -@property (nonatomic, copy) NSMutableArray *testResults; -@property (nonatomic, strong) NSDateFormatter *formatter; -@property (nonatomic, assign) int totalTests; -@property (nonatomic, assign) int totalFailures; -@property (nonatomic, assign) int totalErrors; -@property (nonatomic, assign) double totalTime; - +@interface JUnitReporter () { + NSMutableArray *_testSuites; + NSMutableArray *_testResults; + NSDateFormatter *_formatter; + int _totalTests; + int _totalFailures; + int _totalErrors; + double _totalTime; +} @end #pragma mark Implementation diff --git a/reporters/phabricator/PhabricatorReporter.m b/reporters/phabricator/PhabricatorReporter.m index 8aa15e720..db9fbb228 100644 --- a/reporters/phabricator/PhabricatorReporter.m +++ b/reporters/phabricator/PhabricatorReporter.m @@ -18,11 +18,12 @@ #import "ReporterEvents.h" -@interface PhabricatorReporter () -@property (nonatomic, copy) NSDictionary *currentBuildCommand; -@property (nonatomic, copy) NSMutableArray *currentTargetFailures; -@property (nonatomic, copy) NSMutableArray *results; -@property (nonatomic, copy) NSString *scheme; +@interface PhabricatorReporter () { + NSDictionary *_currentBuildCommand; + NSMutableArray *_currentTargetFailures; + NSMutableArray *_results; + NSString *_scheme; +} @end @implementation PhabricatorReporter diff --git a/reporters/reporters.xcodeproj/project.pbxproj b/reporters/reporters.xcodeproj/project.pbxproj index 27e580272..297f0feee 100644 --- a/reporters/reporters.xcodeproj/project.pbxproj +++ b/reporters/reporters.xcodeproj/project.pbxproj @@ -379,7 +379,9 @@ 2893A94E17960CD400EFBD28 /* Frameworks */, 2893A94D17960CD400EFBD28 /* Products */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; 2893A94D17960CD400EFBD28 /* Products */ = { isa = PBXGroup; diff --git a/reporters/text/TextReporter.m b/reporters/text/TextReporter.m index 895da21e4..4bbd58ffd 100644 --- a/reporters/text/TextReporter.m +++ b/reporters/text/TextReporter.m @@ -167,20 +167,22 @@ - (void)printLine:(NSString *)format, ... NS_FORMAT_FUNCTION(1, 2) @end -@interface TextReporter () -@property (nonatomic, assign) BOOL isPretty; -@property (nonatomic, assign) BOOL canOverwrite; -@property (nonatomic, strong) TestResultCounter *resultCounter; -@property (nonatomic, copy) NSDictionary *currentStatusEvent; -@property (nonatomic, copy) NSDictionary *currentBuildCommandEvent; -@property (nonatomic, assign) BOOL testHadOutput; -@property (nonatomic, assign) BOOL testOutputEndsInNewline; -@property (nonatomic, strong) ReportWriter *reportWriter; -@property (nonatomic, copy) NSMutableArray *failedTests; -@property (nonatomic, copy) NSString *currentBundle; -@property (nonatomic, copy) NSMutableArray *analyzerWarnings; -@property (nonatomic, copy) NSMutableArray *failedBuildEvents; -@property (nonatomic, copy) NSMutableArray *failedOcunitEvents; +@interface TextReporter () { + TestResultCounter *_resultCounter; + NSDictionary *_currentStatusEvent; + NSDictionary *_currentBuildCommandEvent; + BOOL _testHadOutput; + BOOL _testOutputEndsInNewline; + ReportWriter *_reportWriter; + NSMutableArray *_failedTests; + NSString *_currentBundle; + NSMutableArray *_analyzerWarnings; + NSMutableArray *_failedBuildEvents; + NSMutableArray *_failedOcunitEvents; +@protected + BOOL _isPretty; + BOOL _canOverwrite; +} @end @implementation TextReporter @@ -919,8 +921,8 @@ @implementation PrettyTextReporter - (instancetype)init { if (self = [super init]) { - self.isPretty = YES; - self.canOverwrite = YES; + _isPretty = YES; + _canOverwrite = YES; } return self; } @@ -932,7 +934,7 @@ @implementation NoOverwritePrettyTextReporter - (instancetype)init { if (self = [super init]) { - self.isPretty = YES; + _isPretty = YES; } return self; } @@ -944,7 +946,7 @@ @implementation PlainTextReporter - (instancetype)init { if (self = [super init]) { - self.isPretty = NO; + _isPretty = NO; } return self; } diff --git a/xcodebuild-shim/xcodebuild-shim.xcodeproj/project.pbxproj b/xcodebuild-shim/xcodebuild-shim.xcodeproj/project.pbxproj index ecdb868dc..f16017fb8 100644 --- a/xcodebuild-shim/xcodebuild-shim.xcodeproj/project.pbxproj +++ b/xcodebuild-shim/xcodebuild-shim.xcodeproj/project.pbxproj @@ -76,7 +76,9 @@ 287A381016C876A800319E81 /* xcodebuild-fastsettings-shim */, 283CCAB216C2EE7200F2E343 /* xcodebuild-shim */, ); + indentWidth = 2; sourceTree = ""; + tabWidth = 2; }; 283CCAAA16C2EE7200F2E343 /* Products */ = { isa = PBXGroup; diff --git a/xctool/xctool-tests/FakeTaskManager.m b/xctool/xctool-tests/FakeTaskManager.m index 4ec25d47b..e8c7f9b34 100644 --- a/xctool/xctool-tests/FakeTaskManager.m +++ b/xctool/xctool-tests/FakeTaskManager.m @@ -41,11 +41,12 @@ static id NSTask_allocWithZone(id cls, SEL sel, NSZone *zone) (IMP)NSTask_allocWithZone); } -@interface FakeTaskManager () -@property (nonatomic, copy) NSMutableArray *launchedTasks; -@property (nonatomic, copy) NSMutableArray *launchedTasksToBeHidden; -@property (nonatomic, copy) NSMutableArray *launchHandlerBlocks; -@property (nonatomic, assign) BOOL fakeTasksAreEnabled; +@interface FakeTaskManager () { + NSMutableArray *_launchedTasks; + NSMutableArray *_launchedTasksToBeHidden; + NSMutableArray *_launchHandlerBlocks; + BOOL _fakeTasksAreEnabled; +} @end @implementation FakeTaskManager diff --git a/xctool/xctool/EventBuffer.m b/xctool/xctool/EventBuffer.m index 16fc4014e..85a0fbda0 100644 --- a/xctool/xctool/EventBuffer.m +++ b/xctool/xctool/EventBuffer.m @@ -18,9 +18,10 @@ #import "XCToolUtil.h" -@interface EventBuffer () -@property (nonatomic, strong) id underlyingSink; -@property (nonatomic, copy) NSMutableArray *bufferedEventData; +@interface EventBuffer () { + id _underlyingSink; + NSMutableArray *_bufferedEventData; +} @end @implementation EventBuffer @@ -37,7 +38,7 @@ + (NSArray *)wrapSinks:(NSArray *)sinks + (instancetype)eventBufferForSink:(id)reporter { EventBuffer *obj = [[EventBuffer alloc] init]; - obj.underlyingSink = reporter; + obj->_underlyingSink = reporter; return obj; } diff --git a/xctool/xctool/OCTestEventState.m b/xctool/xctool/OCTestEventState.m index 51cbc1e30..14ba7df0f 100644 --- a/xctool/xctool/OCTestEventState.m +++ b/xctool/xctool/OCTestEventState.m @@ -21,12 +21,11 @@ #import "EventGenerator.h" #import "ReporterEvents.h" -@interface OCTestEventState () - -@property (nonatomic, assign) CFTimeInterval beginTime; -@property (nonatomic, copy) NSMutableString *outputToPublish; -@property (nonatomic, copy) NSMutableString *outputAlreadyPublished; - +@interface OCTestEventState () { + CFTimeInterval _beginTime; + NSMutableString *_outputToPublish; + NSMutableString *_outputAlreadyPublished; +} @end @implementation OCTestEventState diff --git a/xctool/xctool/SchemeGenerator.m b/xctool/xctool/SchemeGenerator.m index d98922b2b..a4f66f998 100644 --- a/xctool/xctool/SchemeGenerator.m +++ b/xctool/xctool/SchemeGenerator.m @@ -18,10 +18,10 @@ #import "XCToolUtil.h" -@interface SchemeGenerator () -@property (nonatomic, copy) NSMutableArray *buildables; -@property (nonatomic, copy) NSMutableSet *projectPaths; - +@interface SchemeGenerator () { + NSMutableArray *_buildables; + NSMutableSet *_projectPaths; +} @end @implementation SchemeGenerator { diff --git a/xctool/xctool/SimulatorWrapper/SimulatorWrapper.m b/xctool/xctool/SimulatorWrapper/SimulatorWrapper.m index 5b0d9b48d..a83a85715 100644 --- a/xctool/xctool/SimulatorWrapper/SimulatorWrapper.m +++ b/xctool/xctool/SimulatorWrapper/SimulatorWrapper.m @@ -106,7 +106,9 @@ + (BOOL)runHostAppTests:(NSString *)testHostBundleID }]; } if (appPID == -1) { - *error = launchError; + if (error != nil) { + *error = launchError; + } ReportStatusMessageEnd(reporters, REPORTER_MESSAGE_INFO, @"Failed to launch '%@' on '%@': %@", diff --git a/xctool/xctool/TestRunState.m b/xctool/xctool/TestRunState.m index 36443c19b..3419dd860 100644 --- a/xctool/xctool/TestRunState.m +++ b/xctool/xctool/TestRunState.m @@ -23,11 +23,12 @@ #import "ReporterEvents.h" #import "XCToolUtil.h" -@interface TestRunState () +@interface TestRunState () { + NSMutableString *_outputBeforeTestsStart; +} @property (nonatomic, strong) OCTestSuiteEventState *testSuiteState; @property (nonatomic, strong) OCTestEventState *previousTestState; @property (nonatomic, copy) NSSet *crashReportsAtStart; -@property (nonatomic, copy) NSMutableString *outputBeforeTestsStart; @end @implementation TestRunState