diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-07 00:17:06 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-01-07 00:17:06 +0000 |
commit | dc06b7b7156e0b1e32f32acf0b89925fd1c4b79f (patch) | |
tree | 2b5ce8a97fbf528014914cd56f64f26dde4f4b69 | |
parent | b215d61d9f4c16c864e378c42c7e213e9bd8e27d (diff) | |
download | ruby-dc06b7b7156e0b1e32f32acf0b89925fd1c4b79f.tar.gz |
* bignum.c (bigmul1_karatsuba): avoid overflow that make assertion
fail in certain case. this patch is contributed from Ray Chason
<chasonr at gmail.com> in personal communication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30483 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | bignum.c | 12 |
2 files changed, 12 insertions, 6 deletions
@@ -2,6 +2,12 @@ Fri Jan 7 00:37:35 2011 Tanaka Akira <akr@fsij.org> * string.c: parenthesize macro arguments. +Thu Jan 6 22:42:02 2011 Yukihiro Matsumoto <matz@ruby-lang.org> + + * bignum.c (bigmul1_karatsuba): avoid overflow that make assertion + fail in certain case. this patch is contributed from Ray Chason + <chasonr at gmail.com> in personal communication. + Thu Jan 6 20:55:49 2011 NAKAMURA Usaku <usa@ruby-lang.org> * lib/mkmf.rb (create_makefile): ignore rest from first dot from @@ -2157,14 +2157,14 @@ bigmul1_karatsuba(VALUE x, VALUE y) t3 = bigmul0(xh, yh); i = xn + yn - n; - /* add t3 to middle bytes of the result (z1) */ - bigadd_core(zds + n, i, BDIGITS(t3), big_real_len(t3), zds + n, i); + /* subtract t1 from t3 */ + bigsub_core(BDIGITS(t3), big_real_len(t3), BDIGITS(t1), t1n, BDIGITS(t3), big_real_len(t3)); - /* subtract t1 from middle bytes of the result (z1) */ - bigsub_core(zds + n, i, BDIGITS(t1), t1n, zds + n, i); + /* subtract t2 from t3; t3 is now the middle term of the product */ + if (t2 != Qundef) bigsub_core(BDIGITS(t3), big_real_len(t3), BDIGITS(t2), t2n, BDIGITS(t3), big_real_len(t3)); - /* subtract t2 from middle bytes of the result (z1) */ - if (t2 != Qundef) bigsub_core(zds + n, i, BDIGITS(t2), t2n, zds + n, i); + /* add t3 to middle bytes of the result (z1) */ + bigadd_core(zds + n, i, BDIGITS(t3), big_real_len(t3), zds + n, i); return z; } |