On 05/30/2017 09:30 AM, Vladimir Sementsov-Ogievskiy wrote: > Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> > --- > nbd/client.c | 26 +++++++++++++++++--------- > 1 file changed, 17 insertions(+), 9 deletions(-) > > diff --git a/nbd/client.c b/nbd/client.c > index 3d15596120..52f7981c9c 100644 > --- a/nbd/client.c > +++ b/nbd/client.c > @@ -426,6 +426,21 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc, > return QIO_CHANNEL(tioc); > } > > +static const char *nbd_magic_to_string(char *out, const char *in, > + size_t count) > +{ > + size_t i; > + > + for (i = 0; i < count; ++i) { > + if (in[i] == '\0') { > + out[i] = '\0'; > + break; > + } > + out[i] = qemu_isprint(in[i]) ? in[i] : '.'; > + } > + > + return out; > +}
Do we really need this? > - TRACE("Magic is %c%c%c%c%c%c%c%c", > - qemu_isprint(buf[0]) ? buf[0] : '.', > - qemu_isprint(buf[1]) ? buf[1] : '.', > - qemu_isprint(buf[2]) ? buf[2] : '.', > - qemu_isprint(buf[3]) ? buf[3] : '.', > - qemu_isprint(buf[4]) ? buf[4] : '.', > - qemu_isprint(buf[5]) ? buf[5] : '.', > - qemu_isprint(buf[6]) ? buf[6] : '.', > - qemu_isprint(buf[7]) ? buf[7] : '.'); > + TRACE("Magic is %s", nbd_magic_to_string(print_buf, buf, 9)); Would it be any simpler to just print the received magic as a 64-bit number in hex, instead of trying to string-ize it? Either the client sends the right magic (the usual case), so we don't need to waste time string-izing it, or the client is bogus and sent us garbage (where printing a hex value is just as efficient as string-izing things to see what the garbage actually was). -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature