]> git.ozlabs.org Git - ccan/commitdiff
ccanlint: fix output for async commands.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 22 Sep 2011 04:30:21 +0000 (14:00 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 22 Sep 2011 04:30:21 +0000 (14:00 +0930)
Previously, it was always "", since we left the nul terminator at the
start.

tools/ccanlint/async.c

index 9c7a442ee64fabcbd8a3a581a3f79e85ebbac725..5c2c4da73d31b1929b1dd25fcaa513c1b2337e92 100644 (file)
@@ -148,14 +148,16 @@ static void reap_output(void)
        tlist_for_each_safe(&running, c, next, list) {
                if (FD_ISSET(c->output_fd, &in)) {
                        int old_len, len;
+                       /* This length includes nul terminator! */
                        old_len = talloc_array_length(c->output);
                        c->output = talloc_realloc(c, c->output, char,
                                                   old_len + 1024);
-                       len = read(c->output_fd, c->output + old_len, 1024);
+                       len = read(c->output_fd, c->output + old_len - 1, 1024);
                        if (len < 0)
                                err(1, "Reading from async command");
                        c->output = talloc_realloc(c, c->output, char,
                                                   old_len + len);
+                       c->output[old_len + len - 1] = '\0';
                        if (len == 0) {
                                struct rusage ru;
                                wait4(c->pid, &c->status, 0, &ru);