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

ruby-changes:24377

From: shyouhei <ko1@a...>
Date: Wed, 18 Jul 2012 13:46:19 +0900 (JST)
Subject: [ruby-changes:24377] shyouhei:r36428 (trunk): add casts

shyouhei	2012-07-18 13:46:04 +0900 (Wed, 18 Jul 2012)

  New Revision: 36428

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36428

  Log:
    add casts
    
    * encoding.c (load_encoding): explicit cast  to suppress  warning.
      Though the  cast truncates some bits, from  heuristic analysis I
      believe it is OK to do so here.
    
    * bignum.c (rb_cstr_to_inum): ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/encoding.c

Index: encoding.c
===================================================================
--- encoding.c	(revision 36427)
+++ encoding.c	(revision 36428)
@@ -582,7 +582,7 @@
 
     while (s < e) {
 	if (!ISALNUM(*s)) *s = '_';
-	else if (ISUPPER(*s)) *s = TOLOWER(*s);
+	else if (ISUPPER(*s)) *s = (char)TOLOWER(*s);
 	++s;
     }
     FL_UNSET(enclib, FL_TAINT|FL_UNTRUSTED);
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 36427)
+++ ChangeLog	(revision 36428)
@@ -1,3 +1,11 @@
+Wed Jul 18 12:59:50 2012  URABE Shyouhei  <shyouhei@r...>
+
+	* encoding.c (load_encoding): explicit cast  to suppress  warning.
+	  Though the  cast truncates some bits, from  heuristic analysis I
+	  believe it is OK to do so here.
+
+	* bignum.c (rb_cstr_to_inum): ditto.
+
 Wed Jul 18 12:55:54 2012  NARUSE, Yui  <naruse@r...>
 
 	* lib/benchmark.rb: Fix Benchmark.benchmark output with an empty
Index: bignum.c
===================================================================
--- bignum.c	(revision 36427)
+++ bignum.c	(revision 36428)
@@ -731,7 +731,7 @@
 		if (badcheck) goto bad;
 		break;
 	    }
-	    nondigit = c;
+	    nondigit = (char) c;
 	    continue;
 	}
 	else if ((c = conv_digit(c)) < 0) {
@@ -1036,7 +1036,8 @@
 	bits = BITSPERDIG*RBIGNUM_LEN(x);
     }
 
-    return (long)ceil(bits/log_2[base - 2]);
+    /* @shyouhei note: vvvvvvvvvvvvv this cast is suspicious.  But I believe it is OK, because if that cast loses data, this x value is too big, and should have raised RangeError. */
+    return (long)ceil(((double)bits)/log_2[base - 2]);
 }
 
 static long

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

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