Skip to content

Commit

Permalink
Added stricter build config file, with settings based on http://rentz…
Browse files Browse the repository at this point in the history
…sch.tumblr.com/post/237349423/hoseyifyxcodewarnings-scpt

(Thanks to lhunath for the idea - http://github.com/lhunath/asi-http-request/commit/d28fe4062bc2bb665e3d5828e2266584800f30d2)

Made some changes to fix warnings
Have disabled some settings, may re-enable in future:
* Need formal protocols for delegates, as per llunath's fork
* Should consider renaming S3 methods to prevent the clang warnings

Fixed another issue with test breakage on Mac
  • Loading branch information
pokeb committed Nov 25, 2009
1 parent fc29d80 commit a3b974c
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Classes/ASIFormDataRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ - (void)buildMultipartFormDataPostBody
NSString *endItemBoundary = [NSString stringWithFormat:@"\r\n--%@\r\n",stringBoundary];
NSEnumerator *e = [[self postData] keyEnumerator];
NSString *key;
int i=0;
NSUInteger i=0;
while (key = [e nextObject]) {
[self appendPostString:[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key]];
[self appendPostString:[[self postData] objectForKey:key]];
Expand Down
30 changes: 15 additions & 15 deletions Classes/ASIHTTPRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ - (void)handleBytesAvailable
if ([self needsRedirect]) {
return;
}
int bufferSize = 2048;
long long bufferSize = 2048;
if (contentLength > 262144) {
bufferSize = 65536;
} else if (contentLength > 65536) {
Expand All @@ -2142,13 +2142,13 @@ - (void)handleBytesAvailable
if ([[self class] isBandwidthThrottled]) {
[bandwidthThrottlingLock lock];
if (maxBandwidthPerSecond > 0) {
long long maxSize = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond;
if (maxSize < 0) {
long long maxiumumSize = (long long)maxBandwidthPerSecond-(long long)bandwidthUsedInLastSecond;
if (maxiumumSize < 0) {
// We aren't supposed to read any more data right now, but we'll read a single byte anyway so the CFNetwork's buffer isn't full
bufferSize = 1;
} else if (maxSize/4 < bufferSize) {
} else if (maxiumumSize/4 < bufferSize) {
// We were going to fetch more data that we should be allowed, so we'll reduce the size of our read
bufferSize = maxSize/4;
bufferSize = maxiumumSize/4;
}
}
if (bufferSize < 1) {
Expand Down Expand Up @@ -2350,7 +2350,7 @@ + (void)removeProxyAuthenticationCredentialsFromSessionStore:(NSDictionary *)cre
{
[sessionCredentialsLock lock];
NSMutableArray *sessionCredentialsList = [[self class] sessionProxyCredentialsStore];
int i;
NSUInteger i;
for (i=0; i<[sessionCredentialsList count]; i++) {
NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i];
if ([theCredentials objectForKey:@"Credentials"] == credentials) {
Expand All @@ -2366,7 +2366,7 @@ + (void)removeAuthenticationCredentialsFromSessionStore:(NSDictionary *)credenti
{
[sessionCredentialsLock lock];
NSMutableArray *sessionCredentialsList = [[self class] sessionCredentialsStore];
int i;
NSUInteger i;
for (i=0; i<[sessionCredentialsList count]; i++) {
NSDictionary *theCredentials = [sessionCredentialsList objectAtIndex:i];
if ([theCredentials objectForKey:@"Credentials"] == credentials) {
Expand Down Expand Up @@ -2966,8 +2966,8 @@ + (void)recordBandwidthUsage
bandwidthMeasurementDate = [[NSDate dateWithTimeIntervalSinceNow:1] retain];
bandwidthUsedInLastSecond = 0;

int measurements = [bandwidthUsageTracker count];
unsigned long long totalBytes = 0;
NSUInteger measurements = [bandwidthUsageTracker count];
unsigned long totalBytes = 0;
for (NSNumber *bytes in bandwidthUsageTracker) {
totalBytes += [bytes unsignedLongValue];
}
Expand Down Expand Up @@ -3054,7 +3054,7 @@ + (unsigned long)maxUploadReadLength
[bandwidthThrottlingLock lock];

// We'll split our bandwidth allowance into 4 (which is the default for an ASINetworkQueue's max concurrent operations count) to give all running requests a fighting chance of reading data this cycle
long long toRead = maxBandwidthPerSecond/4;
unsigned long toRead = maxBandwidthPerSecond/4;
if (maxBandwidthPerSecond > 0 && (bandwidthUsedInLastSecond + toRead > maxBandwidthPerSecond)) {
toRead = maxBandwidthPerSecond-bandwidthUsedInLastSecond;
if (toRead < 0) {
Expand Down Expand Up @@ -3100,11 +3100,11 @@ + (NSString*)base64forData:(NSData*)theData {
}
}

NSInteger index = (i / 3) * 4;
output[index + 0] = table[(value >> 18) & 0x3F];
output[index + 1] = table[(value >> 12) & 0x3F];
output[index + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[index + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
NSInteger theIndex = (i / 3) * 4;
output[theIndex + 0] = table[(value >> 18) & 0x3F];
output[theIndex + 1] = table[(value >> 12) & 0x3F];
output[theIndex + 2] = (i + 1) < length ? table[(value >> 6) & 0x3F] : '=';
output[theIndex + 3] = (i + 2) < length ? table[(value >> 0) & 0x3F] : '=';
}

return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
Expand Down
7 changes: 7 additions & 0 deletions Classes/Tests/ASIHTTPRequestTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,11 @@
- (void)testMainThreadDelegateAuthenticationFailure;


- (void)requestStarted:(ASIHTTPRequest *)request;
- (void)requestFinished:(ASIHTTPRequest *)request;
- (void)requestFailed:(ASIHTTPRequest *)request;
- (void)delegateTestStarted:(ASIHTTPRequest *)request;
- (void)delegateTestFinished:(ASIHTTPRequest *)request;
- (void)delegateTestFailed:(ASIHTTPRequest *)request;

@end
20 changes: 16 additions & 4 deletions Classes/Tests/ASIHTTPRequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,16 @@ - (void)testDelegateMethods
GHAssertTrue(started,@"Failed to call the delegate method when the request started");
GHAssertTrue(finished,@"Failed to call the delegate method when the request finished");

// Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:@"http://allseeing-i.com"]];
[request setDelegate:self];
[request setTimeOutSeconds:0.01];
[request start];

[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

GHAssertTrue(failed,@"Failed to call the delegate method when the request failed");

started = NO;
Expand All @@ -95,7 +101,6 @@ - (void)testDelegateMethods
[request setDidFinishSelector:@selector(delegateTestFinished:)];
[request start];

// Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

GHAssertTrue(started,@"Failed to call the delegate method when the request started");
Expand All @@ -107,7 +112,6 @@ - (void)testDelegateMethods
[request setTimeOutSeconds:0.01];
[request start];

// Hacky, but this test won't run on the main thread, we have to hope the delegate methods will be called in this time
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

GHAssertTrue(failed,@"Failed to call the delegate method when the request failed");
Expand Down Expand Up @@ -188,7 +192,7 @@ - (void)testCharacterEncoding
NSArray *IANAEncodings = [NSArray arrayWithObjects:@"UTF-8",@"US-ASCII",@"ISO-8859-1",@"UTF-16",nil];
NSUInteger NSStringEncodings[] = {NSUTF8StringEncoding,NSASCIIStringEncoding,NSISOLatin1StringEncoding,NSUnicodeStringEncoding};

int i;
NSUInteger i;
for (i=0; i<[IANAEncodings count]; i++) {
NSURL *url = [[[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://allseeing-i.com/ASIHTTPRequest/tests/Character-Encoding/%@",[IANAEncodings objectAtIndex:i]]] autorelease];
ASIHTTPRequest *request = [[[ASIHTTPRequest alloc] initWithURL:url] autorelease];
Expand Down Expand Up @@ -394,7 +398,7 @@ - (void)testDownloadProgress
[request start];

// Wait for the progress to catch up
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.25]];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];

BOOL success = (progress > 0.95);
GHAssertTrue(success,@"Failed to properly increment download progress %f != 1.0",progress);
Expand Down Expand Up @@ -1197,6 +1201,14 @@ - (void)asyncSuccess:(ASIHTTPRequest *)request

}


// Will be called on Mac OS
- (void)setDoubleValue:(double)newProgress;
{
progress = (float)newProgress;
}

// Will be called on iPhone OS
- (void)setProgress:(float)newProgress;
{
progress = newProgress;
Expand Down
11 changes: 7 additions & 4 deletions Classes/Tests/ASINetworkQueueTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -335,16 +335,19 @@ - (void)testUploadProgress

}

// Will be called on Mac OS
- (void)setDoubleValue:(double)newProgress;
{
progress = (float)newProgress;
}



- (void)setProgress:(float)newProgress
// Will be called on iPhone OS
- (void)setProgress:(float)newProgress;
{
progress = newProgress;
}



- (void)testFailure
{
complete = NO;
Expand Down
18 changes: 9 additions & 9 deletions Classes/Tests/ASIS3RequestTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ - (void)testAuthenticationHeaderGeneration
{
NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o";
NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82";
NSString *bucket = @"johnsmith";
NSString *exampleBucket = @"johnsmith";

// Test GET
NSString *path = @"/photos/puppy.jpg";
NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000";
ASIS3Request *request = [ASIS3Request requestWithBucket:bucket path:path];
ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path];
[request setDateString:dateString];
[request setSecretAccessKey:exampleSecretAccessKey];
[request setAccessKey:exampleAccessKey];
Expand All @@ -56,7 +56,7 @@ - (void)testAuthenticationHeaderGeneration
// Test PUT
path = @"/photos/puppy.jpg";
dateString = @"Tue, 27 Mar 2007 21:15:45 +0000";
request = [ASIS3Request requestWithBucket:bucket path:path];
request = [ASIS3Request requestWithBucket:exampleBucket path:path];
[request setRequestMethod:@"PUT"];
[request setMimeType:@"image/jpeg"];
[request setDateString:dateString];
Expand All @@ -68,7 +68,7 @@ - (void)testAuthenticationHeaderGeneration

// Test List
dateString = @"Tue, 27 Mar 2007 19:42:41 +0000";
ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:bucket];
ASIS3ListRequest *listRequest = [ASIS3ListRequest listRequestWithBucket:exampleBucket];
[listRequest setPrefix:@"photos"];
[listRequest setMaxResultCount:50];
[listRequest setMarker:@"puppy"];
Expand All @@ -82,7 +82,7 @@ - (void)testAuthenticationHeaderGeneration
// Test fetch ACL
path = @"/?acl";
dateString = @"Tue, 27 Mar 2007 19:44:46 +0000";
request = [ASIS3Request requestWithBucket:bucket path:path];
request = [ASIS3Request requestWithBucket:exampleBucket path:path];
[request setDateString:dateString];
[request setSecretAccessKey:exampleSecretAccessKey];
[request setAccessKey:exampleAccessKey];
Expand All @@ -92,10 +92,10 @@ - (void)testAuthenticationHeaderGeneration

// Test Unicode keys
// (I think Amazon's name for this example is misleading since this test actually only uses URL encoded strings)
bucket = @"dictionary";
exampleBucket = @"dictionary";
path = @"/fran%C3%A7ais/pr%c3%a9f%c3%a8re";
dateString = @"Wed, 28 Mar 2007 01:49:49 +0000";
request = [ASIS3Request requestWithBucket:bucket path:path];
request = [ASIS3Request requestWithBucket:exampleBucket path:path];
[request setDateString:dateString];
[request setSecretAccessKey:exampleSecretAccessKey];
[request setAccessKey:exampleAccessKey];
Expand All @@ -111,10 +111,10 @@ - (void)testFailure
// We're actually going to try with the Amazon example details, but the request will fail because the date is old
NSString *exampleSecretAccessKey = @"uV3F3YluFJax1cknvbcGwgjvx4QpvB+leU8dUj2o";
NSString *exampleAccessKey = @"0PN5J17HBGZHT7JJ3X82";
NSString *bucket = @"johnsmith";
NSString *exampleBucket = @"johnsmith";
NSString *path = @"/photos/puppy.jpg";
NSString *dateString = @"Tue, 27 Mar 2007 19:36:42 +0000";
ASIS3Request *request = [ASIS3Request requestWithBucket:bucket path:path];
ASIS3Request *request = [ASIS3Request requestWithBucket:exampleBucket path:path];
[request setDateString:dateString];
[request setSecretAccessKey:exampleSecretAccessKey];
[request setAccessKey:exampleAccessKey];
Expand Down
4 changes: 4 additions & 0 deletions Mac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
8D1107320486CEB800E47090 /* Mac.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Mac.app; sourceTree = BUILT_PRODUCTS_DIR; };
B50244191025D36B002B13E1 /* ProxyTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProxyTests.h; sourceTree = "<group>"; };
B502441A1025D36B002B13E1 /* ProxyTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProxyTests.m; sourceTree = "<group>"; };
B515507810BD56E800608267 /* strict.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = strict.xcconfig; sourceTree = "<group>"; };
B51791281024BF0F00583567 /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; };
B51E5F39100B829D004A300D /* ASIS3BucketObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIS3BucketObject.h; sourceTree = "<group>"; };
B51E5F3A100B829D004A300D /* ASIS3BucketObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIS3BucketObject.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -178,6 +179,7 @@
29B97315FDCFA39411CA2CEA /* Other Sources */ = {
isa = PBXGroup;
children = (
B515507810BD56E800608267 /* strict.xcconfig */,
B55B5E6E0F7656A40064029C /* main.m */,
B55B5E6F0F7656A40064029C /* Mac_Prefix.pch */,
B55B5ED00F76588D0064029C /* AppDelegate.h */,
Expand Down Expand Up @@ -400,6 +402,7 @@
/* Begin XCBuildConfiguration section */
B55B5EE20F7658C80064029C /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = NO;
Expand Down Expand Up @@ -432,6 +435,7 @@
};
B55B5EE30F7658C80064029C /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = B515507810BD56E800608267 /* strict.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
COPY_PHASE_STRIP = YES;
Expand Down
26 changes: 26 additions & 0 deletions strict.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// strict.xcconfig
// Mac
//
// Created by Ben Copsey on 25/11/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//

GCC_WARN_CHECK_SWITCH_STATEMENTS = YES
GCC_WARN_SHADOW = YES
GCC_WARN_64_TO_32_BIT_CONVERSION = YES
GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES
GCC_WARN_ABOUT_RETURN_TYPE = YES
//GCC_WARN_MISSING_PARENTHESES = YES
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES
//GCC_WARN_ABOUT_MISSING_NEWLINE = YES
GCC_WARN_SIGN_COMPARE = YES
GCC_WARN_STRICT_SELECTOR_MATCH = missing value
GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES
//GCC_WARN_UNDECLARED_SELECTOR = YES
GCC_WARN_UNUSED_FUNCTION = YES
GCC_WARN_UNUSED_LABEL = YES
GCC_WARN_UNUSED_VALUE = YES
GCC_WARN_UNUSED_VARIABLE = YES
GCC_TREAT_WARNINGS_AS_ERRORS = YES
//RUN_CLANG_STATIC_ANALYZER = YES

0 comments on commit a3b974c

Please sign in to comment.