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 <richard.henderson@linaro.org>
Message-Id: <20240412073346.458116-4-richard.henderson@linaro.org>
This commit is contained in:
Richard Henderson 2024-04-12 00:33:22 -07:00
parent f1572ab947
commit 53ee5f551e
3 changed files with 34 additions and 22 deletions

View file

@ -944,13 +944,15 @@ static int vhost_vdpa_set_config_call(struct vhost_dev *dev,
static void vhost_vdpa_dump_config(struct vhost_dev *dev, const uint8_t *config,
uint32_t config_len)
{
int b, len;
char line[QEMU_HEXDUMP_LINE_LEN];
g_autoptr(GString) str = g_string_sized_new(4 * 16);
size_t b, len;
for (b = 0; b < config_len; b += 16) {
len = config_len - b;
qemu_hexdump_line(line, config + b, len);
trace_vhost_vdpa_dump_config(dev, b, line);
for (b = 0; b < config_len; b += len) {
len = MIN(config_len - b, 16);
g_string_truncate(str, 0);
qemu_hexdump_line(str, config + b, len);
trace_vhost_vdpa_dump_config(dev, b, str->str);
}
}