From 9ab54fde00d55f214a151b64db4dc5be93562658 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 19 Jul 2024 08:51:05 +0200 Subject: [PATCH] debug_dump: overflow fix The printout includes pointer, which was at the time of writting supposed to be 32, in which case the line length was: 2 /* 0x */ + 8 /* ptr */ + 1 /* : */ + 3 * 16 /* " XX" */ + 16 /* char repr */ + 5 /* additiona separators */ + 1 /* NL */ = 81 (separators - 2 betweeh group of hexa and char repre, 3 between hexa and char represenatation) With 64 bit pinters, it can be at most 89 bytes. To keep the old length, removed one space between every pair of hexadecimal byte representation - it is still good legible, compatibile with xxd, still keeping the 80 long line.. --- src/debug.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/debug.cpp b/src/debug.cpp index 5897d420b..111423418 100644 --- a/src/debug.cpp +++ b/src/debug.cpp @@ -193,10 +193,12 @@ void debug_dump(const void *lp, int len) /* display each character as hex value */ for (i = start, j = 0; j < 16; p++, i++, j++) { if (i < len) { - snprintf(tmpBuf, sizeof tmpBuf, "%02X ", ((int)(*p) & 0xFF)); + snprintf(tmpBuf, sizeof tmpBuf, "%02X", ((int)(*p) & 0xFF)); strcat(Buff, tmpBuf); } else strcat(Buff, " "); + if (j % 2 == 1) /* space between groups of 2 */ + strcat(Buff, " "); if (j == 7) /* space between groups of 8 */ strcat(Buff, " "); }