Skip to content

Commit

Permalink
receiver object may be changed within NSArray#select! block
Browse files Browse the repository at this point in the history
  • Loading branch information
Watson1978 committed Jul 5, 2012
1 parent d0d0cc6 commit 345184f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion NSArray.m
Expand Up @@ -708,13 +708,20 @@
RETURN_ENUMERATOR(rcv, 0, 0);
CHECK_MUTABLE(rcv);
NSMutableArray *result = [NSMutableArray new];
for (id elem in rcv) {
long len = [rcv count];
for (long i = 0; i < len; i++) {
id elem = [rcv objectAtIndex:i];
VALUE test = rb_yield(OC2RB(elem));
RETURN_IF_BROKEN();
if (!RTEST(test)) {
continue;
}
[result addObject:elem];
const long n = [rcv count];
if (n < len) {
// Array was modified.
len = n;
}
}
if ([result count] == [rcv count]) {
return Qnil;
Expand Down

0 comments on commit 345184f

Please sign in to comment.