Skip to content

Commit 6498db9

Browse files
committed
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..
1 parent 4f3da43 commit 6498db9

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/debug.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,12 @@ void debug_dump(const void *lp, int len)
193193
/* display each character as hex value */
194194
for (i = start, j = 0; j < 16; p++, i++, j++) {
195195
if (i < len) {
196-
snprintf(tmpBuf, sizeof tmpBuf, "%02X ", ((int)(*p) & 0xFF));
196+
snprintf(tmpBuf, sizeof tmpBuf, "%02X", ((int)(*p) & 0xFF));
197197
strcat(Buff, tmpBuf);
198198
} else
199199
strcat(Buff, " ");
200+
if (j % 2 == 1) /* space between groups of 2 */
201+
strcat(Buff, " ");
200202
if (j == 7) /* space between groups of 8 */
201203
strcat(Buff, " ");
202204
}

0 commit comments

Comments
 (0)