From 58b2297da2c8b4975894c12e35a52c27bcf214aa Mon Sep 17 00:00:00 2001 From: nagachika Date: Mon, 19 Mar 2018 17:30:19 +0000 Subject: merge revision(s) 61413: [Backport #14218] force hash values fixable * include/ruby/ruby.h (RB_ST2FIX): force fixable on LLP64 environment. * hash.c (any_hash): ditto. [ruby-core:84395] [Bug #14218] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@62849 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- hash.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'hash.c') diff --git a/hash.c b/hash.c index 4a28b86bae..e8c459067b 100644 --- a/hash.c +++ b/hash.c @@ -198,8 +198,16 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE)) hnum = other_func(a); } out: +#if SIZEOF_LONG < SIZEOF_ST_INDEX_T + if (hnum > 0) + hnum &= (unsigned long)-1 >> 2; + else + hnum |= ~((unsigned long)-1 >> 2); +#else hnum <<= 1; - return (long)RSHIFT(hnum, 1); + hnum = RSHIFT(hnum, 1); +#endif + return (long)hnum; } static st_index_t -- cgit v1.2.3