qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable cha


From: Luiz Capitulino
Subject: Re: [Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars
Date: Tue, 29 Jan 2013 11:39:14 -0200

On Tue, 29 Jan 2013 14:20:30 +0100
Markus Armbruster <address@hidden> wrote:

> Luiz Capitulino <address@hidden> writes:
> 
> > Otherwise we can get funny stuff printed and if the buffer contains
> > a '\0' char it won't be fully printed.
> >
> > Signed-off-by: Luiz Capitulino <address@hidden>
> > ---
> >  hmp.c | 14 ++++++++++++--
> >  1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/hmp.c b/hmp.c
> > index 249b89b..5bfc8bd 100644
> > --- a/hmp.c
> > +++ b/hmp.c
> > @@ -679,8 +679,10 @@ void hmp_memchar_read(Monitor *mon, const QDict *qdict)
> >  {
> >      uint32_t size = qdict_get_int(qdict, "size");
> >      const char *chardev = qdict_get_str(qdict, "device");
> > +    bool print_nl = false;
> >      MemCharRead *meminfo;
> >      Error *errp = NULL;
> > +    int i;
> >  
> >      meminfo = qmp_memchar_read(chardev, size, false, 0, &errp);
> >      if (errp) {
> > @@ -689,8 +691,16 @@ void hmp_memchar_read(Monitor *mon, const QDict *qdict)
> >          return;
> >      }
> >  
> > -    if (meminfo->count > 0) {
> > -        monitor_printf(mon, "%s\n", meminfo->data);
> > +    for (i = 0; i < meminfo->count; i++) {
> > +        char c = meminfo->data[i];
> > +        if (isprint(c) || c == '\n') {
> > +            monitor_printf(mon, "%c", c);
> > +            print_nl = true;
> > +        }
> > +    }
> > +
> > +    if (print_nl) {
> > +        monitor_printf(mon, "\n");
> >      }
> >  
> >      qapi_free_MemCharRead(meminfo);
> 
> Swallows control characters except for '\n'.  Okay if that's what we
> want, but clearly needs to be documented.

Well, the goal here is to be as friendly as possible when printing
this stuff to users. You do improve it, so I'll merge it into my
patch. Except that, I don't see what has to be documented, as documentation
goes to hmp's help message.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]