ruby-changes:62151
From: Yusuke <ko1@a...>
Date: Wed, 8 Jul 2020 10:00:24 +0900 (JST)
Subject: [ruby-changes:62151] ecfc09d053 (master): gc.c: Cast int literal "1" to bits_t
https://git.ruby-lang.org/ruby.git/commit/?id=ecfc09d053 From ecfc09d053dc4bc9d413d94cd10b64aa05e4015b Mon Sep 17 00:00:00 2001 From: Yusuke Endoh <mame@r...> Date: Wed, 8 Jul 2020 09:58:48 +0900 Subject: gc.c: Cast int literal "1" to bits_t ... because shifting by more than 31 bits has undefined behavior (depending upon platform). Coverity Scan found this issue. diff --git a/gc.c b/gc.c index d1af8ba..1e3b6c2 100644 --- a/gc.c +++ b/gc.c @@ -4199,7 +4199,7 @@ gc_page_sweep(rb_objspace_t *objspace, rb_heap_t *heap, struct heap_page *sweep_ https://github.com/ruby/ruby/blob/trunk/gc.c#L4199 /* create guard : fill 1 out-of-range */ bits[BITMAP_INDEX(p)] |= BITMAP_BIT(p)-1; - bits[BITMAP_INDEX(p) + sweep_page->total_slots / BITS_BITLENGTH] |= ~((1 << ((NUM_IN_PAGE(p) + sweep_page->total_slots) % BITS_BITLENGTH)) - 1); + bits[BITMAP_INDEX(p) + sweep_page->total_slots / BITS_BITLENGTH] |= ~(((bits_t)1 << ((NUM_IN_PAGE(p) + sweep_page->total_slots) % BITS_BITLENGTH)) - 1); for (i=0; i < HEAP_PAGE_BITMAP_LIMIT; i++) { bitset = ~bits[i]; -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/