From 26dd237449561f92920e4b9af1b4868f401e4e71 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 25 Jun 2013 03:31:20 +0000 Subject: [PATCH] * 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 --- ChangeLog | 6 ++++++ bignum.c | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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 + + * 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 * 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; }