Fixed CreateHexDump's signedness.
This commit is contained in:
parent
5dee19648d
commit
e1f75ab6d0
@ -216,7 +216,7 @@ protected:
|
|||||||
{
|
{
|
||||||
// A 32-bit integer can be encoded by at most 5 bytes:
|
// A 32-bit integer can be encoded by at most 5 bytes:
|
||||||
unsigned char b[5];
|
unsigned char b[5];
|
||||||
int idx = 0;
|
size_t idx = 0;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
|
b[idx] = (a_Value & 0x7f) | ((a_Value > 0x7f) ? 0x80 : 0x00);
|
||||||
|
@ -531,20 +531,20 @@ AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a
|
|||||||
format binary data this way:
|
format binary data this way:
|
||||||
00001234: 31 32 33 34 35 36 37 38 39 30 61 62 63 64 65 66 1234567890abcdef
|
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 line[512];
|
||||||
char * p;
|
char * p;
|
||||||
char * q;
|
char * q;
|
||||||
|
|
||||||
a_Out.reserve(a_Size / a_LineLength * (18 + 6 * a_LineLength));
|
a_Out.reserve(a_Size / a_BytesPerLine * (18 + 6 * a_BytesPerLine));
|
||||||
for (int i = 0; i < a_Size; i += a_LineLength)
|
for (size_t i = 0; i < a_Size; i += a_BytesPerLine)
|
||||||
{
|
{
|
||||||
int k = a_Size - i;
|
size_t k = a_Size - i;
|
||||||
if (k > a_LineLength)
|
if (k > a_BytesPerLine)
|
||||||
{
|
{
|
||||||
k = a_LineLength;
|
k = a_BytesPerLine;
|
||||||
}
|
}
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
// MSVC provides a "secure" version of sprintf()
|
// 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
|
// Remove the terminating NULL / leftover garbage in line, after the sprintf-ed value
|
||||||
memset(line + Count, 32, sizeof(line) - Count);
|
memset(line + Count, 32, sizeof(line) - Count);
|
||||||
p = line + 10;
|
p = line + 10;
|
||||||
q = p + 2 + a_LineLength * 3 + 1;
|
q = p + 2 + a_BytesPerLine * 3 + 1;
|
||||||
for (int j = 0; j < k; j++)
|
for (size_t j = 0; j < k; j++)
|
||||||
{
|
{
|
||||||
unsigned char c = ((unsigned char *)a_Data)[i + j];
|
unsigned char c = ((unsigned char *)a_Data)[i + j];
|
||||||
p[0] = HEX(c >> 4);
|
p[0] = HEX(c >> 4);
|
||||||
|
@ -64,7 +64,7 @@ extern AString & RawBEToUTF8(const char * a_RawData, int a_NumShorts, AString &
|
|||||||
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
|
extern AString & UTF8ToRawBEUTF16(const char * a_UTF8, size_t a_UTF8Length, AString & a_UTF16);
|
||||||
|
|
||||||
/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
|
/// Creates a nicely formatted HEX dump of the given memory block. Max a_BytesPerLine is 120
|
||||||
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, int a_BytesPerLine);
|
extern AString & CreateHexDump(AString & a_Out, const void * a_Data, size_t a_Size, size_t a_BytesPerLine);
|
||||||
|
|
||||||
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
|
/// Returns a copy of a_Message with all quotes and backslashes escaped by a backslash
|
||||||
extern AString EscapeString(const AString & a_Message); // tolua_export
|
extern AString EscapeString(const AString & a_Message); // tolua_export
|
||||||
|
Loading…
Reference in New Issue
Block a user