[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars
From: |
Luiz Capitulino |
Subject: |
[Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars |
Date: |
Tue, 29 Jan 2013 10:35:35 -0200 |
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);
--
1.8.1.GIT
- [Qemu-devel] [PATCH] hmp: hmp_memchar_read(): skip non-printable chars,
Luiz Capitulino <=