[前][次][番号順一覧][スレッド一覧]

ruby-changes:56549

From: Yusuke <ko1@a...>
Date: Mon, 15 Jul 2019 14:08:41 +0900 (JST)
Subject: [ruby-changes:56549] Yusuke Endoh: 5353401c25 (master): thread.c (rb_thread_shield_waiting_{inc, dec}): prefer long to int

https://git.ruby-lang.org/ruby.git/commit/?id=5353401c25

From 5353401c254a926426d9a289606fad18a755fcd2 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
Date: Mon, 15 Jul 2019 14:02:45 +0900
Subject: thread.c (rb_thread_shield_waiting_{inc,dec}): prefer long to int

`(unsigned int)(THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT)`
is 0xffffffff, and w > 0xffffffff is always true.
Coverity Scan pointed out this issue.

diff --git a/thread.c b/thread.c
index 55df74d..f00b77c 100644
--- a/thread.c
+++ b/thread.c
@@ -4720,14 +4720,14 @@ thread_shield_alloc(VALUE klass) https://github.com/ruby/ruby/blob/trunk/thread.c#L4720
 #define GetThreadShieldPtr(obj) ((VALUE)rb_check_typeddata((obj), &thread_shield_data_type))
 #define THREAD_SHIELD_WAITING_MASK (FL_USER0|FL_USER1|FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6|FL_USER7|FL_USER8|FL_USER9|FL_USER10|FL_USER11|FL_USER12|FL_USER13|FL_USER14|FL_USER15|FL_USER16|FL_USER17|FL_USER18|FL_USER19)
 #define THREAD_SHIELD_WAITING_SHIFT (FL_USHIFT)
-#define rb_thread_shield_waiting(b) (int)((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT)
+#define rb_thread_shield_waiting(b) ((RBASIC(b)->flags&THREAD_SHIELD_WAITING_MASK)>>THREAD_SHIELD_WAITING_SHIFT)
 
 static inline void
 rb_thread_shield_waiting_inc(VALUE b)
 {
-    unsigned int w = rb_thread_shield_waiting(b);
+    unsigned long w = rb_thread_shield_waiting(b);
     w++;
-    if (w > (unsigned int)(THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT))
+    if (w > (THREAD_SHIELD_WAITING_MASK>>THREAD_SHIELD_WAITING_SHIFT))
 	rb_raise(rb_eRuntimeError, "waiting count overflow");
     RBASIC(b)->flags &= ~THREAD_SHIELD_WAITING_MASK;
     RBASIC(b)->flags |= ((VALUE)w << THREAD_SHIELD_WAITING_SHIFT);
@@ -4736,7 +4736,7 @@ rb_thread_shield_waiting_inc(VALUE b) https://github.com/ruby/ruby/blob/trunk/thread.c#L4736
 static inline void
 rb_thread_shield_waiting_dec(VALUE b)
 {
-    unsigned int w = rb_thread_shield_waiting(b);
+    unsigned long w = rb_thread_shield_waiting(b);
     if (!w) rb_raise(rb_eRuntimeError, "waiting count underflow");
     w--;
     RBASIC(b)->flags &= ~THREAD_SHIELD_WAITING_MASK;
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]