mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
8e613749f4
commit
efc7a3a712
3 changed files with 10 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
|||
Wed Jul 29 14:53:32 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* 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 <nobu@ruby-lang.org>
|
||||
|
||||
* internal.h (LIKELY, UNLIKELY): make a boolean to enforce 1 or 0.
|
||||
|
|
6
hash.c
6
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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue