[Libguestfs] [PATCH] Fix verbose packet dumping functions.
Jim Meyering
jim at meyering.net
Thu Sep 17 14:52:33 UTC 2009
Richard W.M. Jones wrote:
...
> Subject: [PATCH 3/5] Fix verbose packet dumping functions.
>
> This code is normally commented out, because it is too verbose
> unless you happen to be debugging the underlying protocol. Because
> it is normally commented out, I found it had bit-rotted slightly.
> This commit fixes the obvious problems.
> ---
> daemon/proto.c | 4 ++--
> src/guestfs.c | 12 ++++++------
> 2 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/daemon/proto.c b/daemon/proto.c
> index 431f219..817a995 100644
> --- a/daemon/proto.c
> +++ b/daemon/proto.c
> @@ -83,10 +83,10 @@ main_loop (int _sock)
>
> #if 0
Looks fine.
You might want to change that "#if 0" to something like
"#if LIBGUESTFS_ENABLE_PACKET_DUMP" so that you can enable it
without modifying the code. Then there'd be less risk of accidentally
committing a change that was required solely for debugging.
> if (verbose) {
> - int i, j;
> + size_t i, j;
>
> for (i = 0; i < len; i += 16) {
> - printf ("%04x: ", i);
> + printf ("%04zx: ", i);
> for (j = i; j < MIN (i+16, len); ++j)
> printf ("%02x ", (unsigned char) buf[j]);
> for (; j < i+16; ++j)
> diff --git a/src/guestfs.c b/src/guestfs.c
> index 17974fd..e9961d1 100644
> --- a/src/guestfs.c
> +++ b/src/guestfs.c
> @@ -1902,18 +1902,18 @@ recv_from_daemon (guestfs_h *g, uint32_t *size_rtn, void **buf_rtn)
> /* Got the full message, caller can start processing it. */
> #if 0
> if (g->verbose) {
> - size_t i, j;
> + ssize_t i, j;
>
> for (i = 0; i < nr; i += 16) {
> - printf ("%04x: ", i);
> + printf ("%04zx: ", i);
> for (j = i; j < MIN (i+16, nr); ++j)
> - printf ("%02x ", (unsigned char) (*buf_rtn)[j]);
> + printf ("%02x ", (*(unsigned char **)buf_rtn)[j]);
> for (; j < i+16; ++j)
> printf (" ");
> printf ("|");
> - for (j = i; j < MIN (i+16, g->nr); ++j)
> - if (isprint ((*buf_rtn)[j]))
> - printf ("%c", (*buf_rtn)[j]);
> + for (j = i; j < MIN (i+16, nr); ++j)
> + if (isprint ((*(char **)buf_rtn)[j]))
> + printf ("%c", (*(char **)buf_rtn)[j]);
> else
> printf (".");
> for (; j < i+16; ++j)
More information about the Libguestfs
mailing list