If NSURLResponse expectedContentLength
doesn't know the length, it will return -1 (the documentation says NSURLResponseUnknownLength
, which is a constant initialized to -1).
You then use a funny way to go from long long
(result type of NSURLResponse expectedContentLength
) via NSNumber numberWithUnsignedInteger
and NSNumber floatValue
to NSUInteger
(argument to NSMutableData initWithCapacity:
). The result is that -1 (internally represented as 0xffffffff) ends up as 4294967295 (internally represented as 0xffffffff as well).
You have to test for NSURLResponseUnknownLength
and use a different initial capacity in that case. And don't use NSNumber
. Simply convert the signed long long
into an unsigned NSUInteger
if it's within the reasonable range.