diff --git a/Source/core/Serialization.cpp b/Source/core/Serialization.cpp index e5d0a01fa..4dfd50069 100644 --- a/Source/core/Serialization.cpp +++ b/Source/core/Serialization.cpp @@ -158,16 +158,16 @@ POP_WARNING() static const TCHAR hex_chars[] = "0123456789abcdef"; - void EXTERNAL ToHexString(const uint8_t object[], const uint16_t length, string& result) + void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result) { ASSERT(object != nullptr); - uint16_t index = static_cast(result.length()); + uint32_t index = static_cast(result.length()); result.resize(index + (length * 2)); result[1] = hex_chars[object[0] & 0xF]; - for (uint16_t i = 0, j = index; i < length; i++) { + for (uint32_t i = 0, j = index; i < length; i++) { if ((object[i] == '\\') && ((i + 3) < length) && (object[i + 1] == 'x')) { result[j++] = object[i + 2]; result[j++] = object[i + 3]; @@ -179,11 +179,12 @@ POP_WARNING() } } - uint16_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint16_t maxLength) { + uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength) + { ASSERT(object != nullptr || maxLength == 0); uint8_t highNibble; uint8_t lowNibble; - uint16_t bufferIndex = 0, strIndex = 0; + uint32_t bufferIndex = 0, strIndex = 0; // assume first character is 0 if length is odd. if (hexString.length() % 2 == 1) { @@ -206,10 +207,10 @@ POP_WARNING() "abcdefghijklmnopqrstuvwxyz" "0123456789+/"; - void ToString(const uint8_t object[], const uint16_t length, const bool padding, string& result) + void ToString(const uint8_t object[], const uint32_t length, const bool padding, string& result) { uint8_t state = 0; - uint16_t index = 0; + uint32_t index = 0; uint8_t lastStuff = 0; while (index < length) { @@ -242,11 +243,11 @@ POP_WARNING() } } - uint16_t FromString(const string& newValue, uint8_t object[], uint16_t& length, const TCHAR* ignoreList) + uint32_t FromString(const string& newValue, uint8_t object[], uint32_t& length, const TCHAR* ignoreList) { uint8_t state = 0; - uint16_t index = 0; - uint16_t filler = 0; + uint32_t index = 0; + uint32_t filler = 0; uint8_t lastStuff = 0; while ((index < newValue.size()) && (filler < length)) { @@ -291,6 +292,14 @@ POP_WARNING() return (index); } + uint16_t FromString(const string& newValue, uint8_t object[], uint16_t& length, const TCHAR* ignoreList) + { + uint32_t tempLength = length; + const uint16_t result = FromString(newValue, object, tempLength, ignoreList); + length = static_cast(tempLength); + return (result); + } + bool CodePointToUTF16(const uint32_t codePoint, uint16_t& lowPart, uint16_t& highPart) { bool translated = true; diff --git a/Source/core/Serialization.h b/Source/core/Serialization.h index ef421677c..85dca41b5 100644 --- a/Source/core/Serialization.h +++ b/Source/core/Serialization.h @@ -255,15 +255,15 @@ POP_WARNING() //------------------------------------------------------------------------ // Serialize: binary buffer //------------------------------------------------------------------------ - void EXTERNAL ToHexString(const uint8_t object[], const uint16_t length, string& result); - uint16_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint16_t maxLength); + void EXTERNAL ToHexString(const uint8_t object[], const uint32_t length, string& result); + uint32_t EXTERNAL FromHexString(const string& hexString, uint8_t* object, const uint32_t maxLength); //------------------------------------------------------------------------ // Serialize: Base64 //------------------------------------------------------------------------ - void EXTERNAL ToString(const uint8_t object[], const uint16_t length, const bool padding, string& result); - + void EXTERNAL ToString(const uint8_t object[], const uint32_t length, const bool padding, string& result); uint16_t EXTERNAL FromString(const string& newValue, uint8_t object[], uint16_t& length, const TCHAR* ignoreList = nullptr); + uint32_t EXTERNAL FromString(const string& newValue, uint8_t object[], uint32_t& length, const TCHAR* ignoreList = nullptr); //------------------------------------------------------------------------ // Codepoint: Operations to extract and convert code points.