From a7dcf580ad6275d3ff730e1b192ec2a410bc5875 Mon Sep 17 00:00:00 2001 From: Kongduino Date: Thu, 26 Jun 2025 01:54:57 +0800 Subject: [PATCH] Update RedirectablePrint.cpp (#7114) Bug fix to my hexDump code. Because `log()` adds a carriage return, hexdump lines were split over 3 lines. This fixes it. --- src/RedirectablePrint.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/RedirectablePrint.cpp b/src/RedirectablePrint.cpp index 07f873864..7c8d77651 100644 --- a/src/RedirectablePrint.cpp +++ b/src/RedirectablePrint.cpp @@ -352,8 +352,8 @@ void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16 for (uint16_t i = 0; i < len; i += 16) { if (i % 128 == 0) log(logLevel, " +------------------------------------------------+ +----------------+"); - char s[] = "| | | |\n"; - uint8_t ix = 1, iy = 52; + char s[] = " | | | |\n"; + uint8_t ix = 5, iy = 56; for (uint8_t j = 0; j < 16; j++) { if (i + j < len) { uint8_t c = buf[i + j]; @@ -367,10 +367,8 @@ void RedirectablePrint::hexDump(const char *logLevel, unsigned char *buf, uint16 } } uint8_t index = i / 16; - if (i < 256) - log(logLevel, " "); - log(logLevel, "%02x", index); - log(logLevel, "."); + sprintf(s, "%03x", index); + s[3] = '.'; log(logLevel, s); } log(logLevel, " +------------------------------------------------+ +----------------+"); @@ -393,4 +391,4 @@ std::string RedirectablePrint::mt_sprintf(const std::string fmt_str, ...) break; } return std::string(formatted.get()); -} \ No newline at end of file +}