Bug #9729

Hash#each が無限ループする

Added by 三村 益隆 about 1 year ago. Updated 11 months ago.

[ruby-dev:48103]
Status:Closed
Priority:Normal
Assignee:Masaya Tarui
ruby -v:ruby 2.2.0dev (2014-04-11 trunk 45566) [x86_64-darwin13] Backport:2.0.0: DONE, 2.1: DONE

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

Duplicates Ruby trunk - Bug #9646: Infinite loop at Hash#each Closed 03/17/2014

Associated revisions

Revision 46721
Added by Tomoyuki Chikanaga 11 months ago

merge revision(s) r45642,r45643: [Backport #9646] [Backport #9729]

* st.c (st_foreach_check): chnage start point of search at check
  from top to current.  [Bug #9646]

* st.c (st_foreach_check): change start point of search at check

Revision 46747
Added by Usaku NAKAMURA 11 months ago

merge revision(s) 45642,45643: [Backport #9646] [Backport #9729]

* st.c (st_foreach_check): chnage start point of search at check
  from top to current.  [Bug #9646]

* st.c (st_foreach_check): change start point of search at check

History

#1 Updated by Nobuyoshi Nakada about 1 year ago

  • Duplicates Bug #9646: Infinite loop at Hash#each added

#2 Updated by Nobuyoshi Nakada about 1 year ago

  • Status changed from Open to Assigned
  • Assignee set to Masaya Tarui

#3 Updated by Masaya Tarui about 1 year 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. [Bug #9646]

#4 Updated by Usaku NAKAMURA 11 months ago

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

#5 Updated by Tomoyuki Chikanaga 11 months 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.

#6 Updated by Usaku NAKAMURA 11 months 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.

Also available in: Atom PDF