Richard W.M. Jones
2009-Sep-17 13:59 UTC
[Libguestfs] [PATCH] Fix verbose packet dumping functions.
-- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw -------------- next part -------------->From 4f6c743041996af4e4e31f8895e5840cbacf4905 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at trick.home.annexia.org> Date: Thu, 17 Sep 2009 14:50:04 +0100 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 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) -- 1.6.2.5
Richard W.M. Jones
2009-Sep-17 14:05 UTC
[Libguestfs] [PATCH] Fix verbose packet dumping functions.
Another thought on this .. does gnulib have (or want) canonical hexdumping code? Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Jim Meyering
2009-Sep-17 14:52 UTC
[Libguestfs] [PATCH] Fix verbose packet dumping functions.
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 0Looks 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)
Possibly Parallel Threads
- [PATCH 0/3] protocol: Abstract out socket operations.
- [PATCH v2] Add progress bars
- Issue with downloading files whose path contains multi-byte utf-8 characters
- [PATCH 0/4] Small refactorings of the protocol layer.
- Issue with downloading files whose path contains multi-byte utf-8 characters