aboutsummaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-31 08:39:20 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-12-31 12:11:45 +0900
commit20a8425aa0f9a947e72b06cbd3a2afe9674dd18f (patch)
treea6f86987877303b2ae99be64334265377f7fa453 /hash.c
parentb2030d4dae3142e3fe6ad79ac1202de5a9f34a5a (diff)
downloadruby-20a8425aa0f9a947e72b06cbd3a2afe9674dd18f.tar.gz
Make any hash values fixable [Bug #17488]
As hnum is an unsigned st_index_t, the result of RSHIFT may not be in the fixable range. Co-authored-by: NeoCat <neocat@neocat.jp>
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/hash.c b/hash.c
index f7bf6bc435..04d9c18dfc 100644
--- a/hash.c
+++ b/hash.c
@@ -223,15 +223,10 @@ any_hash(VALUE a, st_index_t (*other_func)(VALUE))
default:
hnum = other_func(a);
}
-#if SIZEOF_LONG < SIZEOF_ST_INDEX_T
- if (hnum > 0)
- hnum &= (unsigned long)-1 >> 2;
+ if ((SIGNED_VALUE)hnum > 0)
+ hnum &= FIXNUM_MAX;
else
- hnum |= ~((unsigned long)-1 >> 2);
-#else
- hnum <<= 1;
- hnum = RSHIFT(hnum, 1);
-#endif
+ hnum |= FIXNUM_MIN;
return (long)hnum;
}