зеркало из https://github.com/github/ruby.git
* 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:
Родитель
fa1e85c933
Коммит
fa343a796f
|
@ -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.
|
||||
|
|
47
bignum.c
47
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]<<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);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче