hungio / route-me

Automatically exported from code.google.com/p/route-me
0 stars 0 forks source link

RMWebTileImage NSInvalidArgumentException, crash bug #38

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The method is coded incorrectly. It passes in
-(NSInteger)expectedContentLength; directly into NSMutableData's
-initWithCapacity: method. 

The first method can return -1 based on the server that is being accessed
and whether or not it returned a content length header. If no header is
present, the return value is as per the documents:

Return Value
The receiver’s expected content length, or NSURLResponseUnknownLength if
the length can’t be determined.

This constant is -1. When passed into the initWithCapacity: method this
causes an NSInvalidArgumentException to be raised, and the application crashes.

Here is the corrected code:

- (void)connection:(NSURLConnection *)_connection
didReceiveResponse:(NSURLResponse *)response
{
    if (data != nil)
        [data release];

    NSInteger contentLength = [response expectedContentLength];
    if (contentLength < 0) {
        contentLength = 0;
    }
    data = [[NSMutableData alloc] initWithCapacity:contentLength];
}

Original issue reported on code.google.com by db%quarr...@gtempaccount.com on 30 Jan 2009 at 2:02

GoogleCodeExporter commented 8 years ago
Applied suggested patch in r205

Original comment by halmuel...@gmail.com on 27 Feb 2009 at 12:02