From b400da011e434913030aa250594738de5e0ef9e6 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Thu, 23 Jan 2014 08:28:28 -0800 Subject: Fix 64bit issues in logging code. Change-Id: Ia73d0141348b3f74a9949012b0060dd4acb5e3b8 --- runtime/base/logging.cc | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) (limited to 'runtime/base') diff --git a/runtime/base/logging.cc b/runtime/base/logging.cc index 3aabc8d..15554ac 100644 --- a/runtime/base/logging.cc +++ b/runtime/base/logging.cc @@ -177,36 +177,43 @@ void HexDump::Dump(std::ostream& os) const { static const char gHexDigit[] = "0123456789abcdef"; const unsigned char* addr = reinterpret_cast(address_); - char out[76]; /* exact fit */ - unsigned int offset; /* offset to show while printing */ + // 01234560: 00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff 0123456789abcdef + char out[(kBitsPerWord / 4) + /* offset */ + 1 + /* colon */ + (16 * 3) + /* 16 hex digits and space */ + 2 + /* white space */ + 16 + /* 16 characters*/ + 1 /* \0 */ ]; + size_t offset; /* offset to show while printing */ if (show_actual_addresses_) { - offset = reinterpret_cast(addr); + offset = reinterpret_cast(addr); } else { offset = 0; } memset(out, ' ', sizeof(out)-1); - out[8] = ':'; + out[kBitsPerWord / 4] = ':'; out[sizeof(out)-1] = '\0'; size_t byte_count = byte_count_; - int gap = static_cast(offset & 0x0f); + size_t gap = offset & 0x0f; while (byte_count) { - unsigned int line_offset = offset & ~0x0f; + size_t line_offset = offset & ~0x0f; char* hex = out; - char* asc = out + 59; + char* asc = out + (kBitsPerWord / 4) + /* offset */ 1 + /* colon */ + (16 * 3) + /* 16 hex digits and space */ 2 /* white space */; - for (int i = 0; i < 8; i++) { - *hex++ = gHexDigit[line_offset >> 28]; + for (int i = 0; i < (kBitsPerWord / 4); i++) { + *hex++ = gHexDigit[line_offset >> (kBitsPerWord - 4)]; line_offset <<= 4; } hex++; hex++; - int count = std::min(static_cast(byte_count), 16 - gap); - CHECK_NE(count, 0); - CHECK_LE(count + gap, 16); + size_t count = std::min(byte_count, 16 - gap); + CHECK_NE(count, 0U); + CHECK_LE(count + gap, 16U); if (gap) { /* only on first line */ @@ -214,8 +221,8 @@ void HexDump::Dump(std::ostream& os) const { asc += gap; } - int i; - for (i = gap ; i < count+gap; i++) { + size_t i; + for (i = gap ; i < count + gap; i++) { *hex++ = gHexDigit[*addr >> 4]; *hex++ = gHexDigit[*addr & 0x0f]; hex++; -- cgit v1.1