* 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
This commit is contained in:
akr 2013-07-08 16:50:04 +00:00
Родитель fa1e85c933
Коммит fa343a796f
2 изменённых файлов: 32 добавлений и 20 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Tue Jul 9 01:47:16 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (biglsh_bang): Don't shift a BDIGIT with BITSPERDIG bits.
(bigrsh_bang): Ditto.
Tue Jul 9 01:17:57 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigrsh_bang): Fix bignum digits overrun.

Просмотреть файл

@ -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]<<s2);
while (0 < xn) {
*zds-- = num | xds[--xn]>>s3;
num = BIGLO(xds[xn]<<s2);
if (s2 == 0) {
MEMMOVE(xds + s1, xds, BDIGIT, xn - s1);
}
assert(xds <= zds);
*zds = num;
for (i = s1; i > 0; --i)
*zds-- = 0;
else {
zds = xds + xn - 1;
xn -= s1 + 1;
num = BIGLO(xds[xn]<<s2);
while (0 < xn) {
*zds-- = num | xds[--xn]>>s3;
num = BIGLO(xds[xn]<<s2);
}
assert(xds <= zds);
*zds = num;
}
MEMZERO(xds, BDIGIT, s1);
}
static void
@ -4448,16 +4451,20 @@ bigrsh_bang(BDIGIT* xds, long xn, unsigned long shift)
MEMZERO(xds, BDIGIT, xn);
return;
}
i = 0;
zds = xds + s1;
num = *zds++>>s2;
while (i < xn - s1 - 1) {
xds[i++] = BIGLO(*zds<<s3) | num;
num = *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<<s3) | num;
num = *zds++>>s2;
}
assert(i < xn);
xds[i] = num;
}
assert(i < xn);
xds[i] = num;
MEMZERO(xds + xn - s1, BDIGIT, s1);
}