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: Markus Armbruster
Subject: Re: [Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars
Date: Tue, 29 Jan 2013 14:20:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

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.

If not, then something like this:

   for (i = 0; i < meminfo->count; i++) {
       char c = meminfo->data[i];

        if (c == '\') {
            monitor_printf(mon, "\\\\");
        } else if (isprint(c) || c == '\n' || c == '\t') {
            monitor_printf(mon, "%c, c);
        } else {
            monitor_printf(mon, "\\%03o", c);
        }
    }
    if (meminfo->count) {
        monitor_printf(mon, "\n");
    }

Also needs documenting.



reply via email to

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