summaryrefslogtreecommitdiffstats
path: root/arith.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-06-08 05:45:27 -0700
committerKaz Kylheku <kaz@kylheku.com>2016-06-08 05:45:27 -0700
commitede703bad4192140ac637a2bff3603e5a5567510 (patch)
tree0daeb2f068f40f2f9375253aff1f084faf65274f /arith.c
parent72e8f0fdc06255a538078eb50334d584fbf0cebd (diff)
downloadtxr-ede703bad4192140ac637a2bff3603e5a5567510.tar.gz
txr-ede703bad4192140ac637a2bff3603e5a5567510.tar.bz2
txr-ede703bad4192140ac637a2bff3603e5a5567510.zip
Fix leaks in use of MPI and within MPI.
* arith.c (logand, logior, logxor): Use make_ubignum to create an uninitialized bignum, because mp_and, mp_or, and mp_xor expect argument c to be uninitialized, and clobber it by initializing. (comp_trunc): Use make_ubignum for b argument, because mp_trunk_comp initializes it. (lognot, logtrunc): Use make_ubignum for b, because mp_trunc initializes it. * mpi/mpi.c (mp_and, mp_or, mp_xor, mp_comp, mp_trunc_comp, mp_trunc, mp_shift, mp_bit): Do not initialize the tmp that is passed as argument b to mp_2comp, since that function initializes it.
Diffstat (limited to 'arith.c')
-rw-r--r--arith.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/arith.c b/arith.c
index 33942c35..1c3c33ce 100644
--- a/arith.c
+++ b/arith.c
@@ -1771,7 +1771,7 @@ val logand(val a, val b)
case TYPE_PAIR(BGNUM, BGNUM):
if (a == b)
return a;
- c = make_bignum();
+ c = make_ubignum();
if (mp_and(mp(a), mp(b), mp(c)) != MP_OKAY)
goto bad;
return normalize(c);
@@ -1812,7 +1812,7 @@ val logior(val a, val b)
case TYPE_PAIR(BGNUM, BGNUM):
if (a == b)
return a;
- c = make_bignum();
+ c = make_ubignum();
if (mp_or(mp(a), mp(b), mp(c)) != MP_OKAY)
goto bad;
return normalize(c);
@@ -1853,7 +1853,7 @@ val logxor(val a, val b)
case TYPE_PAIR(BGNUM, BGNUM):
if (a == b)
return a;
- c = make_bignum();
+ c = make_ubignum();
if (mp_xor(mp(a), mp(b), mp(c)) != MP_OKAY)
goto bad;
return normalize(c);
@@ -1893,7 +1893,7 @@ static val comp_trunc(val a, val bits)
a = bignum(an);
/* fallthrough */
case BGNUM:
- b = make_bignum();
+ b = make_ubignum();
if (mp_trunc_comp(mp(a), mp(b), bn) != MP_OKAY)
goto bad;
return normalize(b);
@@ -1922,7 +1922,7 @@ val lognot(val a, val bits)
case NUM:
return num_fast(~c_num(a));
case BGNUM:
- b = make_bignum();
+ b = make_ubignum();
if (mp_comp(mp(a), mp(b)) != MP_OKAY)
goto bad;
return normalize(b);
@@ -1956,7 +1956,7 @@ val logtrunc(val a, val bits)
a = bignum(an);
/* fallthrough */
case BGNUM:
- b = make_bignum();
+ b = make_ubignum();
if (mp_trunc(mp(a), mp(b), bn) != MP_OKAY)
goto bad;
return normalize(b);