after updating the xcode to 8.2. I rebuild one of my old project, found the APP will crash when [NSData subdataWithRange], if call it many times (more than 50), it will crash. But the code is normal before, i did nothing change for it.
the code as below:
while (alreadySndLen < fileSize)
{
sndDataLen = (unsigned int)MIN(SEND_SLICE_SIZE, (fileSize - alreadySndLen));
cmdHead.msgOffset = (unsigned int)alreadySndLen;
cmdHead.msgLength = sizeof(FILE_HEAD) + (unsigned int)sndDataLen;
sndRange.location = alreadySndLen;
sndRange.length = sndDataLen;
NSMutableData *cmdData = [[NSMutableData alloc] initWithBytes:&cmdHead length:sizeof(CMD_HEAD)];
[cmdData appendBytes:&fileHead length:sizeof(FILE_HEAD)];
NSLog(@"new file len:%lu", (unsigned long)fileData.length);
NSData *subData = [fileData subdataWithRange:sndRange];
if (nil == subData)
{
NSLog(@"sub data %@ is nil", NSStringFromRange(sndRange));
}
else
{
[cmdData appendData:subData];
}
/
alreadySndLen += sndDataLen;
float progress = (float)alreadySndLen/(float)fileSize;
if (![[MMCMDMgr sharedCMDMgr] uploadFileSliceData:cmdData ofNode:memoID ofSlice:sliceID ofUser:usrID ofType:fileType ofProgress:progress])
{
return FALSE;
}
}