From: Ján Tomko Date: Mon, 8 Aug 2016 13:38:20 +0000 (+0200) Subject: Use a separate buffer for subelements X-Git-Tag: v3.3.0-rc1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51219e11b8c57c7a9755eedd72986269b78ccfb7;p=thirdparty%2Flibvirt.git Use a separate buffer for subelements Instead of figuring out upfront whether will be a single or a pair element, format the subelements into a separate buffer and close early if this buffer is empty. --- diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index fe9b7c7273..a57c395661 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23036,6 +23036,7 @@ virDomainInputDefFormat(virBufferPtr buf, { const char *type = virDomainInputTypeToString(def->type); const char *bus = virDomainInputBusTypeToString(def->bus); + virBuffer childbuf = VIR_BUFFER_INITIALIZER; /* don't format keyboard into migratable XML for backward compatibility */ if (flags & VIR_DOMAIN_DEF_FORMAT_MIGRATABLE && @@ -23058,17 +23059,17 @@ virDomainInputDefFormat(virBufferPtr buf, virBufferAsprintf(buf, "info, flags) || - def->type == VIR_DOMAIN_INPUT_TYPE_PASSTHROUGH) { + virBufferAdjustIndent(&childbuf, virBufferGetIndent(buf, false) + 2); + virBufferEscapeString(&childbuf, "\n", def->source.evdev); + if (virDomainDeviceInfoFormat(&childbuf, &def->info, flags) < 0) + return -1; + + if (!virBufferUse(&childbuf)) { + virBufferAddLit(buf, "/>\n"); + } else { virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - virBufferEscapeString(buf, "\n", def->source.evdev); - if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) - return -1; - virBufferAdjustIndent(buf, -2); + virBufferAddBuffer(buf, &childbuf); virBufferAddLit(buf, "\n"); - } else { - virBufferAddLit(buf, "/>\n"); } return 0;