From 2028b5699adcc4db1e1eb69c334fc126e6f0735b Mon Sep 17 00:00:00 2001 From: Sam Deane Date: Tue, 16 Feb 2016 16:52:15 +0000 Subject: [PATCH] Analyzer warning fixes for situations where a parameter might be nil. --- SUBasicUpdateDriver.m | 8 +++++--- sandbox_service.m | 28 +++++++++++++++------------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index ff5aec77..10a2a158 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -164,9 +164,11 @@ - (void)downloadUpdate { - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]]; - [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; - download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + if (updateItem) { + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[updateItem fileURL]]; + [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + } } - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name diff --git a/sandbox_service.m b/sandbox_service.m index a4fa01d1..b187290a 100644 --- a/sandbox_service.m +++ b/sandbox_service.m @@ -52,19 +52,21 @@ static void peer_event_handler(xpc_connection_t peer, xpc_object_t event) const char *path = xpc_dictionary_get_string(event, "path"); xpc_object_t array = xpc_dictionary_get_value(event, "arguments"); - NSFileManager *manager = [NSFileManager defaultManager]; - NSString *relaunchToolPath = path ? [manager stringWithFileSystemRepresentation:path length:strlen(path)] : nil;; - NSMutableArray *arguments = [NSMutableArray array]; - - for (size_t i = 0; i < xpc_array_get_count(array); i++) { - [arguments addObject: - [NSString stringWithUTF8String:xpc_array_get_string(array, i)]]; - } - - NSError *launchError = nil; - NSRunningApplication *runningApplication = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:relaunchToolPath] options:NSWorkspaceLaunchNewInstance configuration:@{NSWorkspaceLaunchConfigurationArguments:arguments} error:&launchError]; - [runningApplication activateWithOptions:NSApplicationActivateIgnoringOtherApps]; - + if (path) { + NSFileManager *manager = [NSFileManager defaultManager]; + NSString *relaunchToolPath = [manager stringWithFileSystemRepresentation:path length:strlen(path)]; + NSMutableArray *arguments = [NSMutableArray array]; + + for (size_t i = 0; i < xpc_array_get_count(array); i++) { + [arguments addObject: + [NSString stringWithUTF8String:xpc_array_get_string(array, i)]]; + } + + NSError *launchError = nil; + NSRunningApplication *runningApplication = [[NSWorkspace sharedWorkspace] launchApplicationAtURL:[NSURL fileURLWithPath:relaunchToolPath] options:NSWorkspaceLaunchNewInstance configuration:@{NSWorkspaceLaunchConfigurationArguments:arguments} error:&launchError]; + [runningApplication activateWithOptions:NSApplicationActivateIgnoringOtherApps]; + } + // send response to indicate ok xpc_object_t reply = xpc_dictionary_create_reply(event); xpc_connection_send_message(peer, reply);