aboutsummaryrefslogtreecommitdiff
path: root/src/bitstring.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/bitstring.cpp')
-rw-r--r--src/bitstring.cpp10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/bitstring.cpp b/src/bitstring.cpp
index 85f89e2..b3bcde5 100644
--- a/src/bitstring.cpp
+++ b/src/bitstring.cpp
@@ -1,8 +1,10 @@
1#include "bitstring.h" 1#include "bu/bitstring.h"
2#include <stdlib.h> 2#include <stdlib.h>
3#include <stdio.h> 3#include <stdio.h>
4#include <string.h> 4#include <string.h>
5 5
6#include "bu/exceptionbase.h"
7
6#ifdef _WIN32 8#ifdef _WIN32
7#define random() rand() 9#define random() rand()
8#endif 10#endif
@@ -187,6 +189,8 @@ void Bu::BitString::fixup()
187 189
188void Bu::BitString::setBit( long iBit, bool bBitState ) 190void Bu::BitString::setBit( long iBit, bool bBitState )
189{ 191{
192 if( iBit < 0 || iBit >= iBits )
193 throw Bu::ExceptionBase("bit out of range: %d in (0-%d)", iBit, iBits );
190 if( bBitState ) 194 if( bBitState )
191 { 195 {
192 caData[iBit/8] |= (1<<(iBit%8)); 196 caData[iBit/8] |= (1<<(iBit%8));
@@ -342,7 +346,7 @@ bool Bu::BitString::setSize( long iLength, bool bClear )
342 { 346 {
343 // Ok, reallocate and copy... 347 // Ok, reallocate and copy...
344 iBits = iLength; 348 iBits = iLength;
345 long iNewBytes = bitsToBytes( iLength ); 349// long iNewBytes = bitsToBytes( iLength );
346 if( bClear ) 350 if( bClear )
347 { 351 {
348 delete[] caData; 352 delete[] caData;
@@ -352,7 +356,7 @@ bool Bu::BitString::setSize( long iLength, bool bClear )
352 else 356 else
353 { 357 {
354 unsigned char *tmp = caData; 358 unsigned char *tmp = caData;
355 caData = new unsigned char[iBytes]; 359 caData = new unsigned char[iNewBytes];
356 if( iNewBytes < iBytes ) 360 if( iNewBytes < iBytes )
357 { 361 {
358 memcpy( caData, tmp, iNewBytes ); 362 memcpy( caData, tmp, iNewBytes );