aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-25 03:31:20 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-25 03:31:20 +0000
commit26dd237449561f92920e4b9af1b4868f401e4e71 (patch)
tree6113496e97384c6aef996bb9c14b6254c1b9b77f
parentab0a0031839fee694fa59c6b4e23cea88b820e17 (diff)
downloadruby-26dd237449561f92920e4b9af1b4868f401e4e71.tar.gz
* bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=
SIZEOF_BDIGITS. This prevents shift witdth warning from "num <<= BITSPERDIG". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41615 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog6
-rw-r--r--bignum.c9
2 files changed, 14 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 9d194f09dc..12e0016319 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Jun 25 12:28:57 2013 Tanaka Akira <akr@fsij.org>
+
+ * bignum.c (big2ulong): Add code specialized for SIZEOF_LONG <=
+ SIZEOF_BDIGITS.
+ This prevents shift witdth warning from "num <<= BITSPERDIG".
+
Tue Jun 25 12:23:30 2013 Koichi Sasada <ko1@atdot.net>
* gc.c: fix oldgen/remembered_shady counting algorithm.
diff --git a/bignum.c b/bignum.c
index 51ae0f9d20..697d833299 100644
--- a/bignum.c
+++ b/bignum.c
@@ -2413,17 +2413,24 @@ big2ulong(VALUE x, const char *type, int check)
unsigned long num;
BDIGIT *ds;
+ if (len == 0)
+ return 0;
if (BIGSIZE(x) > sizeof(long)) {
if (check)
rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
- len = bdigit_roomof(sizeof(long));
+ if (bdigit_roomof(sizeof(long)) < len)
+ len = bdigit_roomof(sizeof(long));
}
ds = BDIGITS(x);
+#if SIZEOF_LONG <= SIZEOF_BDIGITS
+ num = ds[0];
+#else
num = 0;
while (len--) {
num <<= BITSPERDIG;
num += (unsigned long)ds[len]; /* overflow is already checked */
}
+#endif
return num;
}