Fixing some bignum length comparisons.

This commit is contained in:
Alex Shinn 2013-09-24 15:46:23 +09:00
parent 94615fb11e
commit 7d2b60e1aa

View file

@ -182,8 +182,10 @@ sexp sexp_bignum_fxmul (sexp ctx, sexp d, sexp a, sexp_uint_t b, int offset) {
sexp_luint_t n; sexp_luint_t n;
sexp_gc_var1(tmp); sexp_gc_var1(tmp);
sexp_gc_preserve1(ctx, tmp); sexp_gc_preserve1(ctx, tmp);
if ((! d) || (sexp_bignum_length(d)+offset < len)) if ((! d) || (sexp_bignum_length(d) < len+offset))
d = tmp = sexp_make_bignum(ctx, len); d = tmp = sexp_make_bignum(ctx, len);
else
tmp = d;
data = sexp_bignum_data(d); data = sexp_bignum_data(d);
for (i=0; i<len; i++) { for (i=0; i<len; i++) {
n = (sexp_luint_t)adata[i]*b + carry; n = (sexp_luint_t)adata[i]*b + carry;
@ -191,7 +193,7 @@ sexp sexp_bignum_fxmul (sexp ctx, sexp d, sexp a, sexp_uint_t b, int offset) {
carry = n >> (sizeof(sexp_uint_t)*8); carry = n >> (sizeof(sexp_uint_t)*8);
} }
if (carry) { if (carry) {
if (sexp_bignum_length(d)+offset <= len) if (sexp_bignum_length(d) <= len+offset)
d = sexp_copy_bignum(ctx, NULL, d, len+offset+1); d = sexp_copy_bignum(ctx, NULL, d, len+offset+1);
sexp_bignum_data(d)[len+offset] = carry; sexp_bignum_data(d)[len+offset] = carry;
} }