diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2017-07-26 23:07:16 +0200 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2017-07-26 23:07:16 +0200 |
| commit | 68f7c176565452c5bddf8c20d01a59187ca61a30 (patch) | |
| tree | 97f002ab0047585e82c88e8624a15e5dfa883b35 /src/gui_hexdump.cc | |
| parent | 51587ef41ab94dca2900267a5edcab4345b8f663 (diff) | |
Fix hex print out of values >= 0x80
Diffstat (limited to 'src/gui_hexdump.cc')
| -rw-r--r-- | src/gui_hexdump.cc | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/src/gui_hexdump.cc b/src/gui_hexdump.cc index fbda64d..e7da2d4 100644 --- a/src/gui_hexdump.cc +++ b/src/gui_hexdump.cc @@ -73,8 +73,9 @@ void HexDump::write(AttributedText* text, uint8_t flags, std::string const& str, auto x = tmp2; for (char c = 0; c < 2; ++c) { len = snprintf(tmp, sizeof(tmp), "%02x %02x %02x %02x %02x %02x %02x %02x", - data[i], data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], - data[i + 7]); + data[i] & 0xff, data[i + 1] & 0xff, data[i + 2] & 0xff, + data[i + 3] & 0xff, data[i + 4] & 0xff, data[i + 5] & 0xff, + data[i + 6] & 0xff, data[i + 7] & 0xff); if (flags & CHARS) { x += safe(x, sizeof(tmp2) - (x - tmp2), data + i, 8); } @@ -98,8 +99,9 @@ void HexDump::write(AttributedText* text, uint8_t flags, std::string const& str, auto x = tmp2; if (i + 8 <= length) { len = snprintf(tmp, sizeof(tmp), "%02x %02x %02x %02x %02x %02x %02x %02x", - data[i], data[i + 1], data[i + 2], data[i + 3], data[i + 4], data[i + 5], data[i + 6], - data[i + 7]); + data[i] & 0xff, data[i + 1] & 0xff, data[i + 2] & 0xff, + data[i + 3] & 0xff, data[i + 4] & 0xff, data[i + 5] & 0xff, + data[i + 6] & 0xff, data[i + 7] & 0xff); if (flags & CHARS) { x += safe(x, sizeof(tmp2) - (x - tmp2), data + i, 8); } @@ -108,7 +110,7 @@ void HexDump::write(AttributedText* text, uint8_t flags, std::string const& str, text->append(" "); } for (; i < length; ++i) { - len = snprintf(tmp, sizeof(tmp), "%02x ", data[i]); + len = snprintf(tmp, sizeof(tmp), "%02x ", data[i] & 0xff); if (flags & CHARS) x += safe(x, sizeof(tmp2) - (x - tmp2), data + i, 1); text->append(tmp, len); } @@ -124,7 +126,8 @@ void HexDump::write(AttributedText* text, uint8_t flags, std::string const& str, text->append("\n", 1); } if (flags & ADDRESS) { - len = snprintf(tmp, sizeof(tmp), "%08lx\n", static_cast<unsigned long>(length)); + len = snprintf(tmp, sizeof(tmp), "%08lx\n", + static_cast<unsigned long>(length)); text->append(tmp, len, addr); } } |
