mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[Bug #21513] Raise on converting endless range to set
ref: https://bugs.ruby-lang.org/issues/21513 Before this patch, trying to convert endless range (e.g. `(1..)`) to set (using `to_set`) would hang
This commit is contained in:
parent
d9a14c299f
commit
d4020dd5fa
2 changed files with 22 additions and 0 deletions
8
set.c
8
set.c
|
@ -505,6 +505,14 @@ set_i_initialize(int argc, VALUE *argv, VALUE set)
|
|||
}
|
||||
}
|
||||
else {
|
||||
ID id_size = rb_intern("size");
|
||||
if (rb_obj_is_kind_of(other, rb_mEnumerable) && rb_respond_to(other, id_size)) {
|
||||
VALUE size = rb_funcall(other, id_size, 0);
|
||||
if (RB_TYPE_P(size, T_FLOAT) && RFLOAT_VALUE(size) == INFINITY) {
|
||||
rb_raise(rb_eArgError, "cannot initialize Set from an object with infinite size");
|
||||
}
|
||||
}
|
||||
|
||||
rb_block_call(other, enum_method_id(other), 0, 0,
|
||||
rb_block_given_p() ? set_initialize_with_block : set_initialize_without_block,
|
||||
set);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue