From efc7a3a712f84e3f59f09a89a82f2c36081f0f43 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 29 Jul 2015 05:53:35 +0000 Subject: [PATCH] hash.c: fix float hash * hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a Fixnum, but not a long. [Bug #9381] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51425 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ hash.c | 6 ++++-- test/ruby/test_hash.rb | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8462bd171c..35a8665120 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jul 29 14:53:32 2015 Nobuyoshi Nakada + + * hash.c (rb_any_hash): fix Float hash. rb_dbl_hash() returns a + Fixnum, but not a long. [Bug #9381] + Wed Jul 29 11:07:10 2015 Nobuyoshi Nakada * internal.h (LIKELY, UNLIKELY): make a boolean to enforce 1 or 0. diff --git a/hash.c b/hash.c index 5b13d98ea3..9ae6d9564f 100644 --- a/hash.c +++ b/hash.c @@ -142,7 +142,7 @@ rb_any_hash(VALUE a) } else if (FLONUM_P(a)) { /* prevent pathological behavior: [Bug #10761] */ - return rb_dbl_hash(rb_float_value(a)); + goto flt; } hnum = rb_objid_hash((st_index_t)a); } @@ -153,7 +153,9 @@ rb_any_hash(VALUE a) return RSYMBOL(a)->hashval; } else if (BUILTIN_TYPE(a) == T_FLOAT) { - return rb_dbl_hash(rb_float_value(a)); + flt: + hval = rb_dbl_hash(rb_float_value(a)); + hnum = FIX2LONG(hval); } else { hval = rb_hash(a); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 688dc8689a..d4837ca6cf 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1281,6 +1281,7 @@ class TestHash < Test::Unit::TestCase bad = [ 5, true, false, nil, + 0.0, 1.72723e-77, ].select do |x| hash = {x => bug9381} hash[wrapper.new(x)] != bug9381