From a3ac1be7b7ed48dbaadc57650a17161fc18a5e84 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Sun, 26 Jan 2014 14:42:25 +0100 Subject: Fixed Byte-order reading. The functions would fail on bytes that were above 127. --- src/StringUtils.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 0dbd41c12..3fe75d611 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -833,7 +833,8 @@ AString Base64Encode(const AString & a_Input) short GetBEShort(const char * a_Mem) { - return (((short)a_Mem[0]) << 8) | a_Mem[1]; + const Byte * Bytes = (const Byte *)a_Mem; + return (Bytes[0] << 8) | Bytes[1]; } @@ -842,7 +843,8 @@ short GetBEShort(const char * a_Mem) int GetBEInt(const char * a_Mem) { - return (((int)a_Mem[0]) << 24) | (((int)a_Mem[1]) << 16) | (((int)a_Mem[2]) << 8) | a_Mem[3]; + const Byte * Bytes = (const Byte *)a_Mem; + return (Bytes[0] << 24) | (Bytes[1] << 16) | (Bytes[2] << 8) | Bytes[3]; } -- cgit v1.2.3 From b78c729880705c1bf28f266b087046c4eaed8317 Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 11:56:23 -0700 Subject: Fixed Alignment issue in ByteBuffer --- src/StringUtils.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3fe75d611..3e047fb5c 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -288,13 +288,13 @@ void ReplaceString(AString & iHayStack, const AString & iNeedle, const AString & // Converts a stream of BE shorts into UTF-8 string; returns a ref to a_UTF8 -AString & RawBEToUTF8(short * a_RawData, int a_NumShorts, AString & a_UTF8) +AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) { a_UTF8.clear(); a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = ntohs(*(a_RawData + i)); + int c = GetBEShort(a_RawData + i*2); if (c < 0x80) { a_UTF8.push_back((char)c); @@ -364,10 +364,7 @@ Notice from the original file: #define UNI_MAX_BMP 0x0000FFFF #define UNI_MAX_UTF16 0x0010FFFF -#define UNI_MAX_UTF32 0x7FFFFFFF -#define UNI_MAX_LEGAL_UTF32 0x0010FFFF #define UNI_SUR_HIGH_START 0xD800 -#define UNI_SUR_HIGH_END 0xDBFF #define UNI_SUR_LOW_START 0xDC00 #define UNI_SUR_LOW_END 0xDFFF -- cgit v1.2.3 From 98e15a34a416c31d4689836f4f38161f1270513c Mon Sep 17 00:00:00 2001 From: Tycho Date: Mon, 10 Mar 2014 13:18:53 -0700 Subject: Fixed xofts issues --- src/StringUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3e047fb5c..3f9275798 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -294,7 +294,7 @@ AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString & a_UTF8) a_UTF8.reserve(3 * a_NumShorts / 2); // a quick guess of the resulting size for (int i = 0; i < a_NumShorts; i++) { - int c = GetBEShort(a_RawData + i*2); + int c = GetBEShort(&a_RawData[i * 2]); if (c < 0x80) { a_UTF8.push_back((char)c); -- cgit v1.2.3 From b829c9b14e95f37a3a5ba70fc42cb8cfe9066522 Mon Sep 17 00:00:00 2001 From: Tycho Date: Fri, 14 Mar 2014 07:12:00 -0700 Subject: Fixed a few unneeded breaks --- src/StringUtils.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index 3f9275798..ad622d707 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -454,7 +454,6 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a if (!isLegalUTF8(source, extraBytesToRead + 1)) { return a_UTF16; - break; } // The cases all fall through. See "Note A" below. -- cgit v1.2.3 From 5dee19648d8b3b068698fd1c9cb62e9038bf0e2c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:31:50 +0200 Subject: More Clang warning fixes in the protocols. --- src/StringUtils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index ad622d707..f46730150 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -531,7 +531,7 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef */ -AString & CreateHexDump(AString & a_Out, const void * a_Data, int a_Size, int a_LineLength) +AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_LineLength) { ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max char line[512]; -- cgit v1.2.3 From e1f75ab6d0862d77bf91b588d54acf63fdf20c63 Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 10:42:17 +0200 Subject: Fixed CreateHexDump's signedness. --- src/StringUtils.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index f46730150..a69d8750f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -531,20 +531,20 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a format binary data this way: 00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef */ -AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_LineLength) +AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine) { - ASSERT(a_LineLength <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max + ASSERT(a_BytesPerLine <= 120); // Due to using a fixed size line buffer; increase line[]'s size to lift this max char line[512]; char * p; char * q; - a_Out.reserve(a_Size / a_LineLength * (18 + 6 * a_LineLength)); - for (int i = 0; i < a_Size; i += a_LineLength) + a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine)); + for (size_t i = 0; i < a_Size; i += a_BytesPerLine) { - int k = a_Size - i; - if (k > a_LineLength) + size_t k = a_Size - i; + if (k > a_BytesPerLine) { - k = a_LineLength; + k = a_BytesPerLine; } #ifdef _MSC_VER // MSVC provides a "secure" version of sprintf() @@ -555,8 +555,8 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int // Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value memset(line + Count, 32, sizeof(line) - Count); p = line + 10; - q = p + 2 + a_LineLength * 3 + 1; - for (int j = 0; j < k; j++) + q = p + 2 + a_BytesPerLine * 3 + 1; + for (size_t j = 0; j < k; j++) { unsigned char c = ((unsigned char *)a_Data)[i + j]; p[0] = HEX(c >> 4); -- cgit v1.2.3 From 3590f97e00e570df7a18d953212f33d947f3896c Mon Sep 17 00:00:00 2001 From: madmaxoft Date: Fri, 4 Apr 2014 11:19:57 +0200 Subject: Fixed CreateHexDump's format string. --- src/StringUtils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/StringUtils.cpp') diff --git a/src/StringUtils.cpp b/src/StringUtils.cpp index a69d8750f..33b04505f 100644 --- a/src/StringUtils.cpp +++ b/src/StringUtils.cpp @@ -548,9 +548,9 @@ AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, siz } #ifdef _MSC_VER // MSVC provides a "secure" version of sprintf() - int Count = sprintf_s(line, sizeof(line), "%08x:", i); + int Count = sprintf_s(line, sizeof(line), "%08x:", (unsigned)i); #else - int Count = sprintf(line, "%08x:", i); + int Count = sprintf(line, "%08x:", (unsigned)i); #endif // Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value memset(line + Count, 32, sizeof(line) - Count); -- cgit v1.2.3