Reputation: 664
I have this code:
-(void)getData:(NSString *)data: (id) tv: (id) soc
{
NSLog(@"\nin get data with data\n");
NSLog(data);
After a few hours the app crashes and it reaches in get data with data and doesn't print the data so it's crashing on the print of the data. The debug references the failure in something like a string length function. In XCode, data has a warning that it is not a string literal and potentially insecure. Now my experience tells me the most likely culprit is data is somehow null. But it also printed in the log something that looks like it received a typical message. it said it has 131 bytes from the socket. When i tested and it crashed last time it has 189 bytes. but it never prints it.
The data is sent in from the socket liket this in receive data:
UInt8 buffer[len];
NSLog(@"Received %d bytes from socket %d\n",
len, CFSocketGetNative(s));
CFDataGetBytes(df, range, buffer);
NSString *oldtext = [mTextViewAlias text];
char buffer2[len];
for(int a=0; a<len; a++)
buffer2[a]=buffer[a];
NSMutableData *buffer3 = [[NSMutableData alloc] init];
[buffer3 appendBytes:buffer2 length:len];
NSString *newdata = [[NSString alloc] initWithData: buffer3 encoding:NSASCIIStringEncoding];
and the call to the class method that is crashing when it prints the data is just:
[mytelnet getData:newdata:mTextViewAlias:(__bridge id)(s)];
Could i have a memory leak or something and after a few hours i'm out of memory causing the assignment of new data to be null even if i start out with some 100 bytes? Would it crash only when i tried to print data in the nslog and not earlier if it failed to allocate memory?
Mike
Upvotes: 0
Views: 246
Reputation: 14068
Instead of
NSLog(data);
use
NSLog(@"%@",data);
That may not solve your root cause but you get rid of the warning and may get some more reasonalbe and helpful debug output.
You might get rid of that crash too. Hovever this is not a promise.
Upvotes: 2