From fa343a796fd256fc9098db7fdddf226fe5cbd181 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 8 Jul 2013 16:50:04 +0000 Subject: [PATCH] * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits. (bigrsh_bang): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ bignum.c | 47 +++++++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7b9b116700..327ed87e99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jul 9 01:47:16 2013 Tanaka Akira + + * bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits. + (bigrsh_bang): Ditto. + Tue Jul 9 01:17:57 2013 Tanaka Akira * bignum.c (bigrsh_bang): Fix bignum digits overrun. diff --git a/bignum.c b/bignum.c index 5918cefb7e..b742bb4ac5 100644 --- a/bignum.c +++ b/bignum.c @@ -4417,22 +4417,25 @@ biglsh_bang(BDIGIT *xds, long xn, unsigned long shift) int const s3 = BITSPERDIG-s2; BDIGIT* zds; BDIGIT num; - long i; if (s1 >= xn) { MEMZERO(xds, BDIGIT, xn); return; } - zds = xds + xn - 1; - xn -= s1 + 1; - num = BIGLO(xds[xn]<>s3; - num = BIGLO(xds[xn]< 0; --i) - *zds-- = 0; + else { + zds = xds + xn - 1; + xn -= s1 + 1; + num = BIGLO(xds[xn]<>s3; + num = BIGLO(xds[xn]<>s2; - while (i < xn - s1 - 1) { - xds[i++] = BIGLO(*zds<>s2; + if (s2 == 0) { + MEMMOVE(xds, xds + s1, BDIGIT, xn - s1); + } + else { + i = 0; + zds = xds + s1; + num = *zds++>>s2; + while (i < xn - s1 - 1) { + xds[i++] = BIGLO(*zds<>s2; + } + assert(i < xn); + xds[i] = num; } - assert(i < xn); - xds[i] = num; MEMZERO(xds + xn - s1, BDIGIT, s1); }