Skip to content

Commit

Permalink
Fix "_hexdump buffer size too small (114)" which has been spoiling he…
Browse files Browse the repository at this point in the history
…xdumps

[26/06 23:35:00.478 AD4]: _hexdump buffer size too small (114)
Message repeated 6 times

The problem was that the allocated length for the buffer was based solely on the length of the input string, not taking into account that a single character of input can require a whole line of hexdump output if it spills over to a new line.
  • Loading branch information
Jalle19 committed Jun 27, 2024
1 parent 56beafe commit 25dbfb8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,9 @@ int init_utils(char *arg0) {
}

void _hexdump(char *desc, void *addr, int len) {
int i, pos = 0, bl = (len * 6 < 100) ? 100 : len * 6;
// Each character needs roughly 5 bytes to print. Worst case scenario is
// that one character ends up on a new line, requiring 74 bytes to print.
int i, pos = 0, bl = (len * 5) + 74;
char buff[17];
char buf[bl];
unsigned char *pc = (unsigned char *)addr;
Expand Down

0 comments on commit 25dbfb8

Please sign in to comment.