diff options
author | Sebastian Geerken <devnull@localhost> | 2015-01-31 17:19:59 +0100 |
---|---|---|
committer | Sebastian Geerken <devnull@localhost> | 2015-01-31 17:19:59 +0100 |
commit | 1ca300614dcf31eca1a971f2fbbcdd2a5ae81208 (patch) | |
tree | c800eac7d4543fff2f63e4d50045c91de288972f /lout | |
parent | 20be26d3698eeeeaf2c0a9e55a28831466fc0bd1 (diff) | |
parent | 014a83d2f53cd49bd2540c53ee56f26d880fe2f5 (diff) |
Merge with main repo.
Diffstat (limited to 'lout')
-rw-r--r-- | lout/misc.cc | 6 | ||||
-rw-r--r-- | lout/misc.hh | 2 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lout/misc.cc b/lout/misc.cc index 8d630efc..9b333c93 100644 --- a/lout/misc.cc +++ b/lout/misc.cc @@ -133,6 +133,7 @@ void StringBuffer::clear () BitSet::BitSet(int initBits) { + numBits = initBits; numBytes = bytesForBits(initBits); bits = (unsigned char*)malloc(numBytes * sizeof(unsigned char)); clear(); @@ -146,7 +147,7 @@ BitSet::~BitSet() void BitSet::intoStringBuffer(misc::StringBuffer *sb) { sb->append("["); - for (int i = 0; i < numBytes; i++) + for (int i = 0; i < numBits; i++) sb->append(get(i) ? "1" : "0"); sb->append("]"); } @@ -161,6 +162,9 @@ bool BitSet::get(int i) const void BitSet::set(int i, bool val) { + if (i > numBits) + numBits = i; + if (8 * i >= numBytes) { int newNumBytes = numBytes; while (8 * i >= newNumBytes) diff --git a/lout/misc.hh b/lout/misc.hh index 1bc1c1de..18ac0802 100644 --- a/lout/misc.hh +++ b/lout/misc.hh @@ -581,7 +581,7 @@ class BitSet { private: unsigned char *bits; - int numBytes; + int numBits, numBytes; inline int bytesForBits(int bits) { return bits == 0 ? 1 : (bits + 7) / 8; } |