[ruby-core:95950] [Ruby master Bug#16366] .count on endless range causes infinite loop

From: merch-redmine@...
Date: 2019-11-26 03:59:11 UTC
List: ruby-core #95950
Issue #16366 has been updated by jeremyevans0 (Jeremy Evans).

File enum_count_pass-16366.patch added

Attached is a patch that allows interrupting the iteration.  It uses `rb_thread_check_ints` in each loop iteration for Range#count calls (unless a block is passed, as the block case is already interruptable).

----------------------------------------
Bug #16366: .count on endless range causes infinite loop
https://bugs.ruby-lang.org/issues/16366#change-82786

* Author: duffyjp (Jacob Duffy)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin19]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Out of curiosity, I tried:

``` ruby
(1..).count
```

Which resulted in an unkillable 100% CPU irb session. 

I expected either an exception or maybe `Infinity`

Thanks

---Files--------------------------------
enum_count_pass-16366.patch (765 Bytes)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next