Project

General

Profile

Actions

Bug #9729

closed

Hash#each が無限ループする

Added by takkanm (三村 益隆) about 10 years ago. Updated almost 10 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.2.0dev (2014-04-11 trunk 45566) [x86_64-darwin13]
[ruby-dev:48103]

Description

Hash のキーに配列を使い、
キーが同じ値になるように以下のような操作をすると
Hash#each が無限ループします。

h = {}
h[[]] = 1      # h #=> {[] => 1}
h.keys[0] << 1 # h #=> {[1] => 1}
h[[]] = 1      # h #=> {[1] => 1, [] => 1}
h.keys[1] << 1 # h #=> {[1] => 1, [1] => 1} 

h.each { 1 }   # 無限ループ

このコードは、Ruby 1.9.3-p545 だと、無限ループにならないことを確認しています。

また、以下のような手順で {[1] => 1, [1] => 1} を作った場合は、無限ループになりませんでした。

h = {}
h[[]] = 1      # h #=> {[] => 1}
h[[1]] = 1      # h #=> {[] => 1}
h.keys[0] << 1 # h #=> {[1] => 1, [1] => 1}

h.each { 1 }   # 無限ループにならない

Related issues 1 (0 open1 closed)

Is duplicate of Ruby master - Bug #9646: Infinite loop at Hash#eachClosed03/17/2014Actions

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

  • Is duplicate of Bug #9646: Infinite loop at Hash#each added

Updated by nobu (Nobuyoshi Nakada) about 10 years ago

  • Status changed from Open to Assigned
  • Assignee set to tarui (Masaya Tarui)

Updated by tarui (Masaya Tarui) about 10 years ago

  • Status changed from Assigned to Closed

Applied in changeset r45642.


  • st.c (st_foreach_check): chnage start point of search at check
    from top to current. [ruby-dev:48047] [Bug #9646]

Updated by usa (Usaku NAKAMURA) almost 10 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) almost 10 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE

Backported into ruby_2_1 branch at r46721.

Updated by usa (Usaku NAKAMURA) almost 10 years ago

  • Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE

backported into ruby_2_0_0 at r46747.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0