From a0d43268ca5c34151edb258383e46b30164df844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Tue, 27 Jun 2017 16:27:18 +0200 Subject: [PATCH] Use a separate buffer for subelements Convert virDomainSoundDefFormat to use a separate buffer for subelements. --- src/conf/domain_conf.c | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 24dc12986e..e767711964 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23174,38 +23174,32 @@ virDomainSoundDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainSoundModelTypeToString(def->model); - bool children = false; + virBuffer childBuf = VIR_BUFFER_INITIALIZER; size_t i; + virBufferAdjustIndent(&childBuf, virBufferGetIndent(buf, false) + 2); + if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected sound model %d"), def->model); return -1; } + for (i = 0; i < def->ncodecs; i++) + virDomainSoundCodecDefFormat(&childBuf, def->codecs[i]); + + if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) { + virBufferFreeAndReset(&childBuf); + return -1; + } + + if (virBufferCheckError(&childBuf) < 0) + return -1; + virBufferAsprintf(buf, "ncodecs; i++) { - if (!children) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children = true; - } - virDomainSoundCodecDefFormat(buf, def->codecs[i]); - } - - if (virDomainDeviceInfoNeedsFormat(&def->info, flags)) { - if (!children) { - virBufferAddLit(buf, ">\n"); - virBufferAdjustIndent(buf, 2); - children = true; - } - if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) - return -1; - } - - if (children) { - virBufferAdjustIndent(buf, -2); + if (virBufferUse(&childBuf)) { + virBufferAddLit(buf, ">\n"); + virBufferAddBuffer(buf, &childBuf); virBufferAddLit(buf, "\n"); } else { virBufferAddLit(buf, "/>\n");