ruby-changes:71002
From: Peter <ko1@a...>
Date: Tue, 25 Jan 2022 04:34:30 +0900 (JST)
Subject: [ruby-changes:71002] 87784fdeb2 (master): Keep right operand within width when right shifting
https://git.ruby-lang.org/ruby.git/commit/?id=87784fdeb2 From 87784fdeb2340574d11887474f6e2d9b0d5d3bc3 Mon Sep 17 00:00:00 2001 From: Peter Zhu <peter@p...> Date: Mon, 24 Jan 2022 13:38:15 -0500 Subject: 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. --- gc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 96a99cc81a2..d189c42cde6 100644 --- a/gc.c +++ b/gc.c @@ -4956,7 +4956,7 @@ try_move(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_page, https://github.com/ruby/ruby/blob/trunk/gc.c#L4956 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) { -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/