Skip to content

Commit d7774c0

Browse files
Sean McBrideSean McBride
Sean McBride
authored and
Sean McBride
committed
performed a code review, specifically:
- changed some #include to #import - fixed some NULL -> nil Cocoa coding conventions - added new compiler warnings and fixed some warnings they generated - check for nil from NSTemporaryDirectory - added missing files to unit test and test app targets - added xcconfig files for unit test target - added @Private to some ivars - changes some variables from signed to unsigned as appropriate - changed from base 2 to base 10 measurements of file size, consistent with both the actual meaning of metric prefixes and Apple's new policy as of 10.6 - reduced some unneeded copy-paste of code - fixed failure to check for null from malloc and unneeded check against null before calling free - OSErr was incorrectly used instead of OSStatus - added some consts & statics to global strings - fixed some issues discovered by static analysis - fixed some 64bit issues, mostly related to casting and the use of slightly incorrect types/sizes - some dealloc methods were using accessors, changed to access ivars directly, as per Apple guidelines - removed old NS_DURING, NS_HANDLER, NS_ENDHANDLER macros - fixed a bug where immutable data was being mutated - removed all instance of "== YES" as they are dangerous - removed some redundant nil checks - fixed some leaks - conditionally replaced deprecated method usage - cleanup CF/NSMakeCollectable usage - fixed bug in GC where memory could be collected too early due to lack of strong references when using UTF8String - prevent passing null to CFRelease
1 parent bd80144 commit d7774c0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+307
-281
lines changed

Configurations/ConfigCommon.xcconfig

+13-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ GCC_DEBUGGING_SYMBOLS = full
1414
GCC_PRECOMPILE_PREFIX_HEADER = YES
1515
GCC_PREFIX_HEADER = $(SDKROOT)/System/Library/Frameworks/Cocoa.framework/Headers/Cocoa.h
1616
GCC_FAST_OBJC_DISPATCH = YES
17+
GCC_ENABLE_PASCAL_STRINGS = NO
1718
ARCHS = ppc i386 x86_64
1819

1920
// Enable warnings
@@ -36,4 +37,15 @@ GCC_WARN_UNKNOWN_PRAGMAS = YES
3637
GCC_WARN_UNUSED_VARIABLE = YES
3738
GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES
3839
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
39-
WARNING_CFLAGS = -Wall
40+
GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES
41+
GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES
42+
GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES
43+
GCC_WARN_UNUSED_FUNCTION = YES
44+
GCC_WARN_UNUSED_LABEL = YES
45+
GCC_WARN_UNUSED_VALUE = YES
46+
GCC_WARN_UNUSED_PARAMETER = YES
47+
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
48+
WARNING_CFLAGS = -Wall -Wundef -Wendif-labels -Wpointer-arith -Wcast-align -Wwrite-strings -Wmissing-noreturn -Wmissing-format-attribute -Wpacked -Wredundant-decls -Winline -Wdisabled-optimization -Wformat=2 -Wlarger-than-32768 -Winvalid-pch
49+
50+
// TODO:
51+
// GCC_WARN_UNDECLARED_SELECTOR = YES only 7 warnings

Configurations/ConfigCommonDebug.xcconfig

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
GCC_OPTIMIZATION_LEVEL = 0
44
DEBUG_INFORMATION_FORMAT = dwarf
55
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
6-
SPARKLE_EXTRA_DEBUG = -DDEBUG -fstack-protector -D_FORTIFY_SOURCE=2
7-
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
6+
SPARKLE_EXTRA_DEBUG_10_5_ONLY = -fstack-protector -D_FORTIFY_SOURCE=2
7+
SPARKLE_EXTRA_DEBUG = -DDEBUG
8+
OTHER_CFLAGS = $(SPARKLE_EXTRA_DEBUG)
9+
10+
// Add $(SPARKLE_EXTRA_DEBUG_10_5_ONLY) to SPARKLE_EXTRA_DEBUG if your deployment is 10.5 or greater.
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Unit Test only
2+
3+
INFOPLIST_FILE = Tests/Sparkle Unit Tests-Info.plist
4+
OTHER_LDFLAGS = -framework Cocoa -framework SenTestingKit
5+
PRODUCT_NAME = Sparkle Unit Tests
6+
WRAPPER_EXTENSION = octest
7+
FRAMEWORK_SEARCH_PATHS = $(DEVELOPER_LIBRARY_DIR)/Frameworks
8+
GCC_PREFIX_HEADER = $(SYSTEM_LIBRARY_DIR)/Frameworks/Cocoa.framework/Headers/Cocoa.h
9+
GCC_PRECOMPILE_PREFIX_HEADER = YES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "ConfigCommon.xcconfig"
2+
#include "ConfigCommonDebug.xcconfig"
3+
#include "ConfigUnitTest.xcconfig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "ConfigCommon.xcconfig"
2+
#include "ConfigCommonRelease.xcconfig"
3+
#include "ConfigUnitTest.xcconfig"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "ConfigUnitTestRelease.xcconfig"
2+
3+
GCC_ENABLE_OBJC_GC = required

NTSynchronousTask.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
@interface NTSynchronousTask : NSObject
1313
{
14+
@private
1415
NSTask *mv_task;
1516
NSPipe *mv_outputPipe;
1617
NSPipe *mv_inputPipe;

NTSynchronousTask.m

+10-15
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ - (void)dealloc
5656
{
5757
[[NSNotificationCenter defaultCenter] removeObserver:self];
5858

59-
[self setTask:nil];
60-
[self setOutputPipe:nil];
61-
[self setInputPipe:nil];
62-
[self setOutput:nil];
59+
[mv_task release];
60+
[mv_outputPipe release];
61+
[mv_inputPipe release];
62+
[mv_output release];
6363

6464
[super dealloc];
6565
}
@@ -70,7 +70,7 @@ + (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withAr
7070
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
7171
NSData* result=nil;
7272

73-
NS_DURING
73+
@try
7474
{
7575
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
7676

@@ -81,8 +81,7 @@ + (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withAr
8181

8282
[task release];
8383
}
84-
NS_HANDLER;
85-
NS_ENDHANDLER;
84+
@catch (NSException *localException) { }
8685

8786
[pool drain];
8887

@@ -92,10 +91,6 @@ + (NSData*)task:(NSString*)toolPath directory:(NSString*)currentDirectory withAr
9291
return result;
9392
}
9493

95-
@end
96-
97-
@implementation NTSynchronousTask (Private)
98-
9994
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
10095
{
10196
BOOL success = NO;
@@ -118,12 +113,12 @@ - (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(
118113

119114
[[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, nil]];
120115

121-
NS_DURING
116+
@try
117+
{
122118
[[self task] launch];
123119
success = YES;
124-
NS_HANDLER
125-
;
126-
NS_ENDHANDLER
120+
}
121+
@catch (NSException *localException) { }
127122

128123
if (success)
129124
{

SUAppcast.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
#define SUAPPCAST_H
1111

1212
@class SUAppcastItem;
13-
@interface SUAppcast : NSObject {
13+
@interface SUAppcast : NSObject
14+
{
15+
@private
1416
NSArray *items;
1517
NSString *userAgentString;
1618
id delegate;

SUAppcast.m

+13-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,12 @@ - (void)fetchAppcastFromURL:(NSURL *)url
4040

4141
- (void)download:(NSURLDownload *)download decideDestinationWithSuggestedFilename:(NSString *)filename
4242
{
43-
NSString *destinationFilename = [NSTemporaryDirectory() stringByAppendingPathComponent:filename];
44-
[download setDestination:destinationFilename allowOverwrite:NO];
43+
NSString* destinationFilename = NSTemporaryDirectory();
44+
if (destinationFilename)
45+
{
46+
destinationFilename = [destinationFilename stringByAppendingPathComponent:filename];
47+
[download setDestination:destinationFilename allowOverwrite:NO];
48+
}
4549
}
4650

4751
- (void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path
@@ -52,7 +56,8 @@ - (void)download:(NSURLDownload *)download didCreateDestination:(NSString *)path
5256

5357
- (void)downloadDidFinish:(NSURLDownload *)download
5458
{
55-
CFRelease(download);
59+
if (download)
60+
CFRelease(download);
5661

5762
NSError *error = nil;
5863
NSXMLDocument *document = [[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:downloadFilename] options:0 error:&error];
@@ -62,7 +67,7 @@ - (void)downloadDidFinish:(NSURLDownload *)download
6267
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
6368
[[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil];
6469
#else
65-
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
70+
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil];
6671
#endif
6772
[downloadFilename release];
6873
downloadFilename = nil;
@@ -179,13 +184,14 @@ - (void)downloadDidFinish:(NSURLDownload *)download
179184

180185
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
181186
{
182-
CFRelease(download);
187+
if (download)
188+
CFRelease(download);
183189
if (downloadFilename)
184190
{
185191
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
186192
[[NSFileManager defaultManager] removeFileAtPath:downloadFilename handler:nil];
187193
#else
188-
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:NULL];
194+
[[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil];
189195
#endif
190196
}
191197
[downloadFilename release];
@@ -219,7 +225,7 @@ - (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes
219225
NSXMLElement *node;
220226
NSMutableArray *languages = [NSMutableArray array];
221227
NSString *lang;
222-
NSInteger i;
228+
NSUInteger i;
223229
while ((node = [nodeEnum nextObject]))
224230
{
225231
lang = [[node attributeForName:@"xml:lang"] stringValue];

SUAppcastItem.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
#ifndef SUAPPCASTITEM_H
1010
#define SUAPPCASTITEM_H
1111

12-
@interface SUAppcastItem : NSObject {
12+
@interface SUAppcastItem : NSObject
13+
{
14+
@private
1315
NSString *title;
1416
NSDate *date;
1517
NSString *itemDescription;

SUAppcastItem.m

+8-8
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,14 @@ - (void)setMinimumSystemVersion:(NSString *)systemVersionString
185185

186186
- (void)dealloc
187187
{
188-
[self setTitle:nil];
189-
[self setDate:nil];
190-
[self setItemDescription:nil];
191-
[self setReleaseNotesURL:nil];
192-
[self setDSASignature:nil];
193-
[self setFileURL:nil];
194-
[self setVersionString:nil];
195-
[self setDisplayVersionString:nil];
188+
[title release];
189+
[date release];
190+
[itemDescription release];
191+
[releaseNotesURL release];
192+
[DSASignature release];
193+
[fileURL release];
194+
[versionString release];
195+
[displayVersionString release];
196196
[propertiesDictionary release];
197197
[super dealloc];
198198
}

SUAutomaticUpdateDriver.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#import "SUBasicUpdateDriver.h"
1414

1515
@class SUAutomaticUpdateAlert;
16-
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver {
16+
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver
17+
{
18+
@private
1719
BOOL postponingInstallation, showErrors;
1820
SUAutomaticUpdateAlert *alert;
1921
}

SUBasicUpdateDriver.m

+25-20
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac
9494
}
9595

9696
updateItem = [item retain];
97-
CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
97+
if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast.
9898
if (updateItem == nil) { [self didNotFindUpdate]; return; }
9999

100100
if ([self itemContainsValidUpdate:updateItem])
@@ -105,7 +105,7 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac
105105

106106
- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
107107
{
108-
CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
108+
if (ac) { CFRelease(ac); } // Remember that we're explicitly managing the memory of the appcast.
109109
[self abortUpdateWithError:error];
110110
}
111111

@@ -139,27 +139,31 @@ - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSSt
139139
// We create a temporary directory in /tmp and stick the file there.
140140
// Not using a GUID here because hdiutil (for DMGs) for some reason chokes on GUIDs. Too long? I really have no idea.
141141
NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]];
142-
NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
143-
int cnt=1;
144-
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
142+
NSString *tempDir = NSTemporaryDirectory();
143+
if (tempDir)
145144
{
146-
tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]];
147-
}
145+
tempDir = [tempDir stringByAppendingPathComponent:prefix];
146+
unsigned int cnt=1;
147+
while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
148+
{
149+
tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %u", prefix, cnt++]];
150+
}
148151

149152
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
150-
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
153+
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
151154
#else
152-
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
155+
BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:nil];
153156
#endif
154-
if (!success)
155-
{
156-
// Okay, something's really broken with /tmp
157-
[download cancel];
158-
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]];
157+
if (!success)
158+
{
159+
// Okay, something's really broken with /tmp
160+
[download cancel];
161+
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]];
162+
}
163+
164+
downloadPath = [[tempDir stringByAppendingPathComponent:name] retain];
165+
[download setDestination:downloadPath allowOverwrite:YES];
159166
}
160-
161-
downloadPath = [[tempDir stringByAppendingPathComponent:name] retain];
162-
[download setDestination:downloadPath allowOverwrite:YES];
163167
}
164168

165169
- (void)downloadDidFinish:(NSURLDownload *)d
@@ -226,16 +230,17 @@ - (void)installUpdate
226230
{
227231
if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)])
228232
[[updater delegate] updater:updater willInstallUpdate:updateItem];
233+
229234
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
230-
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
235+
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
231236
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
232237
// Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
233238
NSError *error = nil;
234239
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
235240
[[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
236241
if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
237242
#else
238-
[[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL];
243+
[[NSFileManager defaultManager] removeItemAtPath:targetPath error:nil];
239244
if ([[NSFileManager defaultManager] copyItemAtPath:relaunchPathToCopy toPath:targetPath error:&error])
240245
#endif
241246
relaunchPath = [targetPath retain];
@@ -292,7 +297,7 @@ - (void)cleanUp
292297
#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4
293298
[[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil];
294299
#else
295-
[[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL];
300+
[[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:nil];
296301
#endif
297302
}
298303

SUConstants.h

+18-18
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,26 @@
1111
#define SUCONSTANTS_H
1212

1313

14-
extern NSString *SUUpdaterWillRestartNotification;
15-
extern NSString *SUTechnicalErrorInformationKey;
14+
extern NSString *const SUUpdaterWillRestartNotification;
15+
extern NSString *const SUTechnicalErrorInformationKey;
1616

17-
extern NSString *SUFeedURLKey;
18-
extern NSString *SUHasLaunchedBeforeKey;
19-
extern NSString *SUShowReleaseNotesKey;
20-
extern NSString *SUSkippedVersionKey;
21-
extern NSString *SUScheduledCheckIntervalKey;
22-
extern NSString *SULastCheckTimeKey;
23-
extern NSString *SUPublicDSAKeyKey;
24-
extern NSString *SUPublicDSAKeyFileKey;
25-
extern NSString *SUAutomaticallyUpdateKey;
26-
extern NSString *SUAllowsAutomaticUpdatesKey;
27-
extern NSString *SUEnableAutomaticChecksKey;
28-
extern NSString *SUEnableAutomaticChecksKeyOld;
29-
extern NSString *SUEnableSystemProfilingKey;
30-
extern NSString *SUSendProfileInfoKey;
31-
extern NSString *SULastProfileSubmitDateKey;
17+
extern NSString *const SUFeedURLKey;
18+
extern NSString *const SUHasLaunchedBeforeKey;
19+
extern NSString *const SUShowReleaseNotesKey;
20+
extern NSString *const SUSkippedVersionKey;
21+
extern NSString *const SUScheduledCheckIntervalKey;
22+
extern NSString *const SULastCheckTimeKey;
23+
extern NSString *const SUPublicDSAKeyKey;
24+
extern NSString *const SUPublicDSAKeyFileKey;
25+
extern NSString *const SUAutomaticallyUpdateKey;
26+
extern NSString *const SUAllowsAutomaticUpdatesKey;
27+
extern NSString *const SUEnableAutomaticChecksKey;
28+
extern NSString *const SUEnableAutomaticChecksKeyOld;
29+
extern NSString *const SUEnableSystemProfilingKey;
30+
extern NSString *const SUSendProfileInfoKey;
31+
extern NSString *const SULastProfileSubmitDateKey;
3232

33-
extern NSString *SUSparkleErrorDomain;
33+
extern NSString *const SUSparkleErrorDomain;
3434
// Appcast phase errors.
3535
extern OSStatus SUAppcastParseError;
3636
extern OSStatus SUNoUpdateError;

0 commit comments

Comments
 (0)