diff options
author | Peter Zhu <[email protected]> | 2022-01-24 13:38:15 -0500 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2022-01-24 14:34:12 -0500 |
commit | 87784fdeb2340574d11887474f6e2d9b0d5d3bc3 (patch) | |
tree | 33ee4cbad99720fe6ee16d83108826794689415e /gc.c | |
parent | 97ab2599f395fac001d4453c7b3ea9f131485b6f (diff) |
Keep right operand within width when right shifting
NUM_IN_PAGE could return a value much larger than 64. According to the
C11 spec 6.5.7 paragraph 3 this is undefined behavior:
> If the value of the right operand is negative or is greater than or
> equal to the width of the promoted left operand, the behavior is
> undefined.
On most platforms, this is usually not a problem as the architecture
will mask off all out-of-range bits.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5478
Diffstat (limited to 'gc.c')
-rw-r--r-- | gc.c | 2 |
1 files changed, 1 insertions, 1 deletions
@@ -4956,7 +4956,7 @@ try_move(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_page, bits_t bits = mark_bits[index] & ~pin_bits[index]; - bits >>= NUM_IN_PAGE(p); + bits >>= NUM_IN_PAGE(p) % BITS_BITLENGTH; if (try_move_plane(objspace, heap, sweep_page, (uintptr_t)p, bits, dest)) return 1; if (index == 0) { |