Old snapshot `bigint-2006.05.03'; see the ChangeLog file.
authorMatt McCutchen <hashproduct@gmail.com>
Sat, 27 Jan 2007 21:06:20 +0000 (16:06 -0500)
committerMatt McCutchen <hashproduct@gmail.com>
Sat, 27 Jan 2007 21:06:20 +0000 (16:06 -0500)
BigUnsigned.cc
BigUnsignedInABase.cc
ChangeLog

index 33fe0af..ecf1055 100644 (file)
@@ -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.
index f2a6f79..4692a0a 100644 (file)
@@ -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;
 }
index 7aaced1..759e629 100644 (file)
--- 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
++===================================================================+