Hi!

I recently needed to match some patterns but I encountered a problematic
situation.

Please, can anyone explain to me why does the following program
consistently segfault after 50000 characters? I'm running 10.9.5...

    #import <Cocoa/Cocoa.h>

    int main () {
        NSString *pattern =
@"(1+)|(2+)|(3+)|(4+)|(5+)|(6+)|(7+)|(8+)|(9+)|(0+)|(a+)";
        NSRegularExpression *expression = [NSRegularExpression
regularExpressionWithPattern:pattern options:0 error:nil];
        for (NSUInteger i = 0; i < 100000; i += 10000) {
            NSString *string = [@"" stringByPaddingToLength:i withString:@"a"
startingAtIndex:0];
            NSTextCheckingResult *result = [expression
firstMatchInString:string options:0 range:NSMakeRange(0, i)];
            NSLog(@"%@", NSStringFromRange([result range]));
        }
        return 0;
    }

It says:

    {0, 0}
    {0, 10000}
    {0, 20000}
    {0, 30000}
    {0, 40000}
    {0, 50000}
    Segmentation fault: 11

Thanks in advance!
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to