* bignum.c (bigxor_int): Fix a buffer over read.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9be51267b5
commit
1457ee2ce4
@ -1,3 +1,7 @@
|
|||||||
|
Wed Jun 26 12:48:22 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (bigxor_int): Fix a buffer over read.
|
||||||
|
|
||||||
Wed Jun 26 12:13:12 2013 Tanaka Akira <akr@fsij.org>
|
Wed Jun 26 12:13:12 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (bigand_int): Consider negative values.
|
* bignum.c (bigand_int): Consider negative values.
|
||||||
|
23
bignum.c
23
bignum.c
@ -4873,6 +4873,10 @@ bigxor_int(VALUE x, long y)
|
|||||||
sign = (y >= 0) ? 1 : 0;
|
sign = (y >= 0) ? 1 : 0;
|
||||||
xds = BDIGITS(x);
|
xds = BDIGITS(x);
|
||||||
zn = xn = RBIGNUM_LEN(x);
|
zn = xn = RBIGNUM_LEN(x);
|
||||||
|
#if SIZEOF_BDIGITS < SIZEOF_LONG
|
||||||
|
if (zn < bdigit_roomof(SIZEOF_LONG))
|
||||||
|
zn = bdigit_roomof(SIZEOF_LONG);
|
||||||
|
#endif
|
||||||
z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign));
|
z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign));
|
||||||
zds = BDIGITS(z);
|
zds = BDIGITS(z);
|
||||||
|
|
||||||
@ -4880,19 +4884,22 @@ bigxor_int(VALUE x, long y)
|
|||||||
i = 1;
|
i = 1;
|
||||||
zds[0] = xds[0] ^ y;
|
zds[0] = xds[0] ^ y;
|
||||||
#else
|
#else
|
||||||
{
|
for (i = 0; i < xn; i++) {
|
||||||
long num = y;
|
zds[i] = xds[i] ^ BIGLO(y);
|
||||||
|
y = BIGDN(y);
|
||||||
for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) {
|
|
||||||
zds[i] = xds[i] ^ BIGLO(num);
|
|
||||||
num = BIGDN(num);
|
|
||||||
}
|
}
|
||||||
|
for (; i < zn; i++) {
|
||||||
|
zds[i] = (RBIGNUM_SIGN(x) ? 0 : BDIGMAX) ^ BIGLO(y);
|
||||||
|
y = BIGDN(y);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
while (i < xn) {
|
for (; i < xn; i++) {
|
||||||
zds[i] = sign ? xds[i] : BIGLO(~xds[i]);
|
zds[i] = sign ? xds[i] : BIGLO(~xds[i]);
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
for (; i < zn; i++) {
|
||||||
|
zds[i] = sign ^ RBIGNUM_SIGN(x) ? BDIGMAX : 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!RBIGNUM_SIGN(z)) get2comp(z);
|
if (!RBIGNUM_SIGN(z)) get2comp(z);
|
||||||
return bignorm(z);
|
return bignorm(z);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user