From: "mame (Yusuke Endoh)" Date: 2022-06-18T02:56:18+00:00 Subject: [ruby-core:108991] [Ruby master Bug#18767] IO.foreach hangs up when passes limit=0 Issue #18767 has been updated by mame (Yusuke Endoh). Status changed from Rejected to Open Okay reopened. Sorry, I overlooked the fact that `IO#each_line(0)` raises an error. IMHO, it is reasonable for `IO#readlines(0)` to raise an exception. If not, it just gets stuck until the memory is exhausted. I'm unsure about `IO#each_line(0)`. ---------------------------------------- Bug #18767: IO.foreach hangs up when passes limit=0 https://bugs.ruby-lang.org/issues/18767#change-98100 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * ruby -v: 3.0.3 * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- `IO.foreach` behaves in an unexpected way in a corner case when passes 0 as a limit parameter. It never stops and hangs up. ```ruby IO.foreach('file.txt', 0) { |s| p s } "" "" "" "" "" "" "" "" "" "" ``` Expected behavior - to raise ArgumentError "invalid limit: 0" like it does the `IO.readlines` method. I observe this behavior on 2.6, 2.7, and 3.0. Didn't check on 3.1 and master though. -- https://bugs.ruby-lang.org/ Unsubscribe: