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)];
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;
}
}
the function is split file to many slice and to send. If send 3 small file, no problem; if 1 big file(bigger than 8M), no problem; if more than 1 big file, it will crash when split the second file. I already check the range, it don't have problem. and the most important is that it is normal in the old version xcode.
please help me find out the reason.
thanks!