From be1bdfe2b1863ad12b104fadb6bbbb4524724146 Mon Sep 17 00:00:00 2001 From: Matt McCutchen Date: Sat, 27 Jan 2007 16:06:20 -0500 Subject: [PATCH] Old snapshot `bigint-2006.05.03'; see the ChangeLog file. --- BigUnsigned.cc | 3 ++- BigUnsignedInABase.cc | 3 ++- ChangeLog | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/BigUnsigned.cc b/BigUnsigned.cc index 33fe0af..ecf1055 100644 --- a/BigUnsigned.cc +++ b/BigUnsigned.cc @@ -562,8 +562,9 @@ void BigUnsigned::divideWithRemainder(const BigUnsigned &b, BigUnsigned &q) { * amusing story of this section of code. */ Index origLen = len; // Save real length. + // 2006.05.03: Copy the number and then change the length! + allocateAndCopy(len + 1); // Get the space. len++; // Increase the length. - allocateAndCopy(len); // Get the space. blk[origLen] = 0; // Zero the extra block. // work2 holds part of the result of a subtraction; see above. diff --git a/BigUnsignedInABase.cc b/BigUnsignedInABase.cc index f2a6f79..4692a0a 100644 --- a/BigUnsignedInABase.cc +++ b/BigUnsignedInABase.cc @@ -117,6 +117,7 @@ BigUnsignedInABase::operator std::string() const { s[symbolNumInString] = char('A' + theDigit - 10); } std::string s2(s); - delete s; + // 2006.05.03: This needs to be [] to match the allocation + delete [] s; return s2; } diff --git a/ChangeLog b/ChangeLog index 7aaced1..759e629 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,10 @@ Change Log ========== These entries tell you what was added, fixed, or improved in each version as compared to the previous one. In case you haven't noticed, a version number roughly corresponds to the release date of that version in `YYYY.MM.DD[.N]' format, where `.N' goes `.2', `.3', etc. if there are multiple versions on the same day. +2006.05.03 +---------- +I ran the sample program using valgrind and discovered a `delete s' that should be `delete [] s' and a `len++' before an `allocateAndCopy(len)' that should have been after an `allocateAndCopy(len + 1)'. I fixed both. Yay for valgrind! + 2006.05.01 ---------- I fixed incorrect results reported by Mohand Mezmaz and related memory corruption on platforms where Blk is bigger than int. I replaced (1 << x) with (Blk(1) << x) in two places in BigUnsigned.cc. @@ -65,4 +69,4 @@ Brad Spencer pointed out a memory leak in `BigUnsigned::divide'. It is fixed in --------- After months of inactivity, I fixed a bug in the `BigInteger' division routine; thanks to David Allen for reporting the bug. I also added simple routines for decimal output to `std::ostream's, and there is a demo that prints out powers of 3. -+===================================================================+ \ No newline at end of file ++===================================================================+ -- 2.34.1