Re: sigbus on rangeOfString:
Re: sigbus on rangeOfString:
- Subject: Re: sigbus on rangeOfString:
- From: Enrico Pancaldi <email@hidden>
- Date: Wed, 27 Feb 2002 13:10:07 +0100
If you use "test.\n", you also have to use
[string setString:[string substringFromIndex:(range.location+ 6 )]];
otherwise you don't reach the end of the string after 2 loops, and
the third time you call rangeOfString:, range.location becomes
NSNotFound, which is 0x7fffffff, that is not in the string.
I think that calling substringToIndex: with this index, tells
malloc to copy (see access) some kind of protected memory (kernel?
maybe someone else could be more specific).
Enrico
On Wednesday, February 27, 2002, at 07:02 AM, Darin Duphorne wrote:
Why does the following work, but when I replace range=[string
rangeOfString:@"\n"]; with range=[string
rangeOfString:@"test.\n"]; I get a sigbus and *** malloc[2832]:
error: Can't allocate region?
NSMutableString *string;
NSMutableString *result;
NSRange range;
string=[[NSMutableString alloc] initWithString:@" This is a
test.\n This is only a test.\n"];
result=[[NSMutableString alloc] init];
while ([string length]>0)
{
range=[string rangeOfString:@"\n"];
[result appendString:[string substringToIndex:range.location]];
[result appendString:@"crlf"];
[string setString:[string substringFromIndex:(range.location+1)]];
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.