libxl_qmp: fix qmp_next to cope with multiple lines read in a single buffer
authorStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 27 Jan 2012 17:58:20 +0000 (17:58 +0000)
committerStefano Stabellini <stefano.stabellini@eu.citrix.com>
Fri, 27 Jan 2012 17:58:20 +0000 (17:58 +0000)
qmp_next doesn't handle multiple lines read together in a single
buffer correctly at the moment.  This patch fixes it.

Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_qmp.c

index f125b17fe34423bfabb7fca5a6e51ac257d5d4a1..a43838d85a664183dd0c0b073e417e0775e1f653 100644 (file)
@@ -408,17 +408,18 @@ static int qmp_next(libxl__gc *gc, libxl__qmp_handler *qmp)
             char *end = NULL;
             if (incomplete) {
                 size_t current_pos = s - incomplete;
-                incomplete_size += rd;
                 incomplete = libxl__realloc(gc, incomplete,
-                                            incomplete_size + 1);
-                incomplete = strncat(incomplete, qmp->buffer, rd);
+                                            incomplete_size + rd);
+                strncat(incomplete + incomplete_size, qmp->buffer, rd);
                 s = incomplete + current_pos;
+                incomplete_size += rd;
                 s_end = incomplete + incomplete_size;
             } else {
                 incomplete = libxl__strndup(gc, qmp->buffer, rd);
                 incomplete_size = rd;
                 s = incomplete;
                 s_end = s + rd;
+                rd = 0;
             }
 
             end = strstr(s, "\r\n");