Skip to content
Browse files

[fix #122] receiver object may be changed within NSArray#each block

  • Loading branch information...
1 parent 85f5996 commit 4ea6d4b6b843983a383e847bf900fd24352b5452 @Watson1978 Watson1978 committed Jul 5, 2012
Showing with 8 additions and 2 deletions.
  1. +8 −2 NSArray.m
View
10 NSArray.m
@@ -462,9 +462,15 @@
nsary_each(id rcv, SEL sel)
{
RETURN_ENUMERATOR(rcv, 0, 0);
- for (id item in rcv) {
- rb_yield(OC2RB(item));
+ long len = [rcv count];
+ for (long i = 0; i < len; i++) {
+ rb_yield(OC2RB([rcv objectAtIndex:i]));
RETURN_IF_BROKEN();
+ const long n = [rcv count];
+ if (n < len) {
+ // Array was modified.
+ len = n;
+ }
}
return (VALUE)rcv;
}

0 comments on commit 4ea6d4b

Please sign in to comment.
Something went wrong with that request. Please try again.