If you read the ICU docs on regular expressions you'll see that it sets an
8MB limit on head size when evaluating. My guess is that you've run into
this and NSRegularExpression misses a return code somewhere.

But your pattern is really suboptimal for what you're trying to accomplish.
For example, this pattern is functionally equivalent and doesn't cause a
crash for me:

    @"(([0-9a])\\2*)"

That matches a single character, and then the same character 0 or more
times.

On Mon, Dec 15, 2014 at 10:38 AM, ecir hana <ecir.h...@gmail.com> wrote:
>
> 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 (Cocoa-dev@lists.apple.com)
>
> 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/stephen.butler%40gmail.com
>
> This email sent to stephen.but...@gmail.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to