From 53ee5f551e5743516c90a662425276cae4cf0aeb Mon Sep 17 00:00:00 2001 From: Richard Henderson Date: Fri, 12 Apr 2024 00:33:22 -0700 Subject: util/hexdump: Use a GString for qemu_hexdump_line Allocate a new, or append to an existing GString instead of using a fixed sized buffer. Require the caller to determine the length of the line -- do not bound len here. Signed-off-by: Richard Henderson Message-Id: <20240412073346.458116-4-richard.henderson@linaro.org> --- include/qemu/cutils.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'include/qemu') diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h index c5dea63..14a3285 100644 --- a/include/qemu/cutils.h +++ b/include/qemu/cutils.h @@ -282,12 +282,17 @@ static inline const char *yes_no(bool b) */ int parse_debug_env(const char *name, int max, int initial); -/* - * Hexdump a line of a byte buffer into a hexadecimal/ASCII buffer +/** + * qemu_hexdump_line: + * @str: GString into which to append + * @buf: buffer to dump + * @len: number of bytes to dump + * + * Append @len bytes of @buf as hexadecimal into @str. + * If @str is NULL, allocate a new string and return it; + * otherwise return @str. */ -#define QEMU_HEXDUMP_LINE_BYTES 16 /* Number of bytes to dump */ -#define QEMU_HEXDUMP_LINE_LEN 75 /* Number of characters in line */ -void qemu_hexdump_line(char *line, const void *bufptr, size_t len); +GString *qemu_hexdump_line(GString *str, const void *buf, size_t len); /* * Hexdump a buffer to a file. An optional string prefix is added to every line -- cgit v1.1