[Libguestfs] [PATCH] trace: Print empty list correctly.

Richard W.M. Jones rjones at redhat.com
Wed Jun 22 09:38:50 UTC 2011


We keep finding bugs in the trace code long after it was added ...

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
New in Fedora 11: Fedora Windows cross-compiler. Compile Windows
programs, test, and build Windows installers. Over 70 libraries supprt'd
http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
-------------- next part --------------
>From 56b94f5f6aa7981533ad867cc908c6e9cca2ba42 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Wed, 22 Jun 2011 10:36:44 +0100
Subject: [PATCH 1/3] trace: Print empty list correctly.

Empty lists returned by RStringList and RHashtable functions
were incorrectly printed as [""].

Fix this so they are printed as [] instead.
---
 generator/generator_c.ml |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/generator/generator_c.ml b/generator/generator_c.ml
index 8208306..7aa472b 100644
--- a/generator/generator_c.ml
+++ b/generator/generator_c.ml
@@ -942,12 +942,14 @@ trace_send_line (guestfs_h *g)
      | RBufferOut _ ->
          pr "%s  guestfs___print_BufferOut (trace_fp, %s, *size_r);\n" indent rv
      | RStringList _ | RHashtable _ ->
-         pr "%s  fputs (\"[\\\"\", trace_fp);\n" indent;
+         pr "%s  fputs (\"[\", trace_fp);\n" indent;
          pr "%s  for (i = 0; %s[i]; ++i) {\n" indent rv;
-         pr "%s    if (i > 0) fputs (\"\\\", \\\"\", trace_fp);\n" indent;
+         pr "%s    if (i > 0) fputs (\", \", trace_fp);\n" indent;
+         pr "%s    fputs (\"\\\"\", trace_fp);\n" indent;
          pr "%s    fputs (%s[i], trace_fp);\n" indent rv;
+         pr "%s    fputs (\"\\\"\", trace_fp);\n" indent;
          pr "%s  }\n" indent;
-         pr "%s  fputs (\"\\\"]\", trace_fp);\n" indent;
+         pr "%s  fputs (\"]\", trace_fp);\n" indent;
      | RStruct (_, typ) ->
          (* XXX There is code generated for guestfish for printing
           * these structures.  We need to make it generally available
-- 
1.7.5.2



More information about the Libguestfs mailing list