diff --git a/ChangeLog b/ChangeLog index 6e9e316c7e..58e9f285cd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -Tue Aug 27 16:51:21 2013 Nobuyoshi Nakada +Tue Aug 27 16:56:50 2013 Nobuyoshi Nakada + + * enumerator.c (enumerator_size): use rb_check_funcall() instead of + respond_to? and call. * enumerator.c (enumerator_each): ensure that argument array size does not overflow at appending. diff --git a/enumerator.c b/enumerator.c index a83c0533d7..6f3de864a0 100644 --- a/enumerator.c +++ b/enumerator.c @@ -1007,19 +1007,19 @@ static VALUE enumerator_size(VALUE obj) { struct enumerator *e = enumerator_ptr(obj); + int argc = 0; + const VALUE *argv = NULL; + VALUE size; if (e->size_fn) { return (*e->size_fn)(e->obj, e->args, obj); } - if (rb_respond_to(e->size, id_call)) { - if (e->args) { - int argc = (int)RARRAY_LEN(e->args); - VALUE *argv = RARRAY_PTR(e->args); - return rb_funcall2(e->size, id_call, argc, argv); - } else { - return rb_funcall(e->size, id_call, 0); - } + if (e->args) { + argc = (int)RARRAY_LEN(e->args); + argv = RARRAY_RAWPTR(e->args); } + size = rb_check_funcall(e->size, id_call, argc, argv); + if (size != Qundef) return size; return e->size; }