From 4df33b759c5c48926ff99d73b98c7e848656db93 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 18 Dec 2013 00:04:25 +0100 Subject: [PATCH 1/3] Network - char[] unpacking. Fixed correct unpacking on char[]. Fixed not clearing string in translator unpack function. --- Code/Network/NetworkAPI/Translator.cpp | 4 +++- Code/Network/NetworkDependencies/Packing.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index e321f31e..6ae26a58 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -44,7 +44,7 @@ struct Translator::PrivateData headerString.push_back(it->second.type); } - message.PackShort(size, bytes); + message.PackShort(headerString.size(), bytes); size += 2; for(int i = 0; i < (int)headerString.size(); i++) @@ -221,6 +221,8 @@ void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol) bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes) { + privateData->headerString.clear(); + if(!privateData->UnpackHeader(protocol, bytes)) { return false; diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index b6903a0a..0c1e642d 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -282,7 +282,7 @@ namespace Oyster char* UnpackCStr(unsigned char buffer[]) { short len = UnpackS(buffer); - char* str = new char[len]; + char* str = new char[len+1]; buffer += 2; for(int i = 0; i < len; i++) @@ -290,6 +290,8 @@ namespace Oyster str[i] = buffer[i]; } + str[len] = '\0'; + return str; } From e1d0150ef14198e7b8c078facc2d0ee276fd085f Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 18 Dec 2013 00:07:24 +0100 Subject: [PATCH 2/3] Network - OysterByte += should now work correctly. --- .../NetworkDependencies/OysterByte.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Code/Network/NetworkDependencies/OysterByte.cpp b/Code/Network/NetworkDependencies/OysterByte.cpp index 7cbbde58..ac6923a2 100644 --- a/Code/Network/NetworkDependencies/OysterByte.cpp +++ b/Code/Network/NetworkDependencies/OysterByte.cpp @@ -60,13 +60,14 @@ unsigned char* OysterByte::GetByteArray() void OysterByte::AddSize(unsigned int size) { - int oldSize = this->size; - this->size += size; + int newCapacity = this->size + size; - if(this->size >= capacity) + if(newCapacity >= capacity) { - IncreaseCapacity(oldSize); + IncreaseCapacity(newCapacity); } + + this->size += size; } void OysterByte::SetBytes(unsigned char* bytes) @@ -113,17 +114,17 @@ OysterByte::operator unsigned char*() OysterByte& OysterByte::operator +=(const OysterByte& obj) { int newSize = this->size + obj.size; - + if(newSize >= (int)capacity) { - IncreaseCapacity(this->size); + IncreaseCapacity(newSize); } for(int i = size, j = 0; i < newSize; i++, j++) { this->byteArray[i] = obj.byteArray[j]; } - + this->size = newSize; return *this; @@ -133,12 +134,12 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj) // 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]; - for(int i = 0; i < (int)oldSize; i++) + for(int i = 0; i < (int)this->size; i++) { temp[i] = byteArray[i]; } From fc8dba6610e87ff197f8c569400fbd713e96fc9f Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Wed, 18 Dec 2013 00:08:50 +0100 Subject: [PATCH 3/3] Network - Fixed Unpackb. Changed Unpackb to "*buffer" instead of "buffer". --- Code/Network/NetworkDependencies/Packing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Network/NetworkDependencies/Packing.cpp b/Code/Network/NetworkDependencies/Packing.cpp index 0c1e642d..41d059a3 100644 --- a/Code/Network/NetworkDependencies/Packing.cpp +++ b/Code/Network/NetworkDependencies/Packing.cpp @@ -169,7 +169,7 @@ namespace Oyster //bool (1-bit) bool Unpackb(unsigned char buffer[]) { - return buffer; + return *buffer; } //char (8-bit)