diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 03:31:20 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-06-25 03:31:20 +0000 |
commit | 26dd237449561f92920e4b9af1b4868f401e4e71 (patch) | |
tree | 6113496e97384c6aef996bb9c14b6254c1b9b77f | |
parent | ab0a0031839fee694fa59c6b4e23cea88b820e17 (diff) | |
download | ruby-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-- | ChangeLog | 6 | ||||
-rw-r--r-- | bignum.c | 9 |
2 files changed, 14 insertions, 1 deletions
@@ -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. @@ -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; } |