Skip to content

Commit

Permalink
debug_dump: overflow fix
Browse files Browse the repository at this point in the history
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..
  • Loading branch information
MartinPulec committed Jul 22, 2024
1 parent 4f3da43 commit 6498db9
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, " ");
}
Expand Down

0 comments on commit 6498db9

Please sign in to comment.