Network - OysterByte += should now work correctly.

This commit is contained in:
Pontus Fransson 2013-12-18 00:07:24 +01:00
parent 4df33b759c
commit e1d0150ef1
1 changed files with 11 additions and 10 deletions

View File

@ -60,13 +60,14 @@ unsigned char* OysterByte::GetByteArray()
void OysterByte::AddSize(unsigned int size) void OysterByte::AddSize(unsigned int size)
{ {
int oldSize = this->size; int newCapacity = this->size + size;
this->size += size;
if(this->size >= capacity) if(newCapacity >= capacity)
{ {
IncreaseCapacity(oldSize); IncreaseCapacity(newCapacity);
} }
this->size += size;
} }
void OysterByte::SetBytes(unsigned char* bytes) void OysterByte::SetBytes(unsigned char* bytes)
@ -116,7 +117,7 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
if(newSize >= (int)capacity) if(newSize >= (int)capacity)
{ {
IncreaseCapacity(this->size); IncreaseCapacity(newSize);
} }
for(int i = size, j = 0; i < newSize; i++, j++) for(int i = size, j = 0; i < newSize; i++, j++)
@ -133,12 +134,12 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
// Private // // Private //
///////////// /////////////
void OysterByte::IncreaseCapacity(unsigned int oldSize) void OysterByte::IncreaseCapacity(unsigned int newCapacity)
{ {
capacity = size * 2; capacity = newCapacity * 2;
unsigned char* temp = new unsigned char[capacity]; unsigned char* temp = new unsigned char[capacity];
for(int i = 0; i < (int)oldSize; i++) for(int i = 0; i < (int)this->size; i++)
{ {
temp[i] = byteArray[i]; temp[i] = byteArray[i];
} }