diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-03 16:01:14 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-08-03 16:01:14 +0000 |
commit | 092511bac76a4aca95e15107c67deb16272154c5 (patch) | |
tree | 4a5aa8fcf280a4e8ea6dbbb835ae38205b844444 /bignum.c | |
parent | b3be3c29c47fd9b570e5649bdf46d1a8f08aa3a0 (diff) | |
download | ruby-092511bac76a4aca95e15107c67deb16272154c5.tar.gz |
* bignum.c (big2str_karatsuba): Don't allocate new temporary buffer
if the buffer is enough for current invocation.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -4383,12 +4383,13 @@ big2str_karatsuba(struct big2str_struct *b2s, BDIGIT *xds, size_t xn, memset(b2s->ptr, '0', len); b2s->ptr += len; } - if (wn < bn * 4 + BIGDIVREM_EXTRA_WORDS) { + rn = bn; + qn = xn+BIGDIVREM_EXTRA_WORDS; + if (wn < rn + qn) { wn = bn * 4 + BIGDIVREM_EXTRA_WORDS; + assert(rn + qn <= wn); wds = ALLOCV_N(BDIGIT, tmpw, wn); } - rn = bn; - qn = xn+BIGDIVREM_EXTRA_WORDS; rds = wds; qds = wds+rn; bary_divmod(qds, qn, rds, rn, xds, xn, bds, bn); |