[libvirt] [PATCH 00/19] util: buffer: Use glib's GString internally

Converting to glib's helpers allows us to greatly simplify the error handling from virBuffer. Peter Krempa (19): util: buffer: Simplify convoluted condition util: buffer: Use 'cleanup' as label name in virBufferAddBuffer util: buffer: Simplify escape buffer allocations virsh: Reimplement _vshCalloc using g_malloc0_n util: alloc: drop xalloc_oversized macro util: buffer: Don't treat missing truncation in virBufferTrim as usage error util: buffer: Simplify handling of indent overflows tests: virbuffer: Drop 'infinite loop' tests tests: virbuffer: Remove unused test data struct util: buffer: Split getting of effective indent out of virBufferGetIndent util: sysinfo: Use virXMLFormatElement and infrastructure in virSysinfoFormat util: virbuffer: Remove @dynamic from virBufferGetIndent util: buffer: Properly URLencode strings util: buffer: Encode URIs with upper case hex characters util: buffer: Reimplement virBuffer internals using glib's GString util: buffer: Remove error handling internals util: buffer: Remove virBufferError util: buffer: Remove virBufferCheckError util: xml: Make virXMLFormatElement void src/bhyve/bhyve_command.c | 3 - src/bhyve/bhyve_driver.c | 5 - src/conf/capabilities.c | 16 - src/conf/checkpoint_conf.c | 3 - src/conf/cpu_conf.c | 7 - src/conf/domain_addr.c | 2 - src/conf/domain_capabilities.c | 1 - src/conf/domain_conf.c | 154 ++++----- src/conf/interface_conf.c | 3 - src/conf/network_conf.c | 5 +- src/conf/node_device_conf.c | 3 - src/conf/nwfilter_conf.c | 9 - src/conf/secret_conf.c | 3 - src/conf/snapshot_conf.c | 3 - src/conf/storage_conf.c | 12 - src/conf/virnetworkobj.c | 3 - src/conf/virnetworkportdef.c | 3 - src/conf/virnwfilterbindingdef.c | 3 - src/conf/virnwfilterbindingobj.c | 3 - src/conf/virsavecookie.c | 3 - src/cpu/cpu_map.c | 2 - src/cpu/cpu_x86.c | 10 - src/esx/esx_driver.c | 12 - src/esx/esx_util.c | 6 - src/esx/esx_vi.c | 15 - src/esx/esx_vi_methods.c | 3 - src/hyperv/hyperv_driver.c | 3 - src/hyperv/hyperv_wmi.c | 10 - src/libvirt_private.syms | 3 +- src/libxl/libxl_conf.c | 5 - src/libxl/libxl_driver.c | 2 - src/libxl/libxl_migration.c | 3 - src/libxl/xen_common.c | 13 - src/libxl/xen_xl.c | 9 - src/libxl/xen_xm.c | 3 - src/locking/lock_driver_sanlock.c | 3 - src/lxc/lxc_container.c | 3 - src/lxc/lxc_controller.c | 3 - src/lxc/lxc_driver.c | 2 - src/lxc/lxc_fuse.c | 4 - src/network/bridge_driver.c | 6 - src/node_device/node_device_udev.c | 3 - src/nwfilter/nwfilter_ebiptables_driver.c | 8 - src/nwfilter/nwfilter_gentech_driver.c | 6 - src/nwfilter/nwfilter_learnipaddr.c | 5 - src/phyp/phyp_driver.c | 4 - src/qemu/qemu_capabilities.c | 3 +- src/qemu/qemu_command.c | 130 -------- src/qemu/qemu_domain.c | 28 +- src/qemu/qemu_driver.c | 2 - src/qemu/qemu_migration_cookie.c | 3 - src/qemu/qemu_monitor_json.c | 3 - src/rpc/virnetlibsshsession.c | 6 - src/rpc/virnetsocket.c | 8 - src/rpc/virnetsshsession.c | 6 - src/security/virt-aa-helper.c | 11 - src/storage/storage_backend_rbd.c | 6 - src/storage/storage_util.c | 13 - src/util/viralloc.h | 19 -- src/util/virbitmap.c | 7 - src/util/virbuffer.c | 361 +++++++--------------- src/util/virbuffer.h | 30 +- src/util/vircommand.c | 11 +- src/util/virconf.c | 6 - src/util/virdnsmasq.c | 6 - src/util/virfilecache.c | 3 - src/util/virlog.c | 8 - src/util/virnetdevopenvswitch.c | 3 - src/util/virpidfile.c | 7 - src/util/virqemu.c | 3 - src/util/virresctrl.c | 4 +- src/util/virstoragefile.c | 3 - src/util/virstring.c | 5 - src/util/virsysinfo.c | 24 +- src/util/virsystemd.c | 6 - src/util/viruri.c | 3 - src/util/virxml.c | 19 +- src/util/virxml.h | 5 +- src/vmx/vmx.c | 3 - src/vz/vz_driver.c | 5 - tests/cputest.c | 4 - tests/networkxml2firewalltest.c | 3 - tests/nwfilterebiptablestest.c | 21 -- tests/nwfilterxml2firewalltest.c | 3 - tests/qemublocktest.c | 6 - tests/qemumonitorjsontest.c | 6 - tests/qemumonitortestutils.c | 2 - tests/testutils.c | 2 - tests/testutilsqemuschema.c | 2 +- tests/vboxsnapshotxmltest.c | 5 - tests/virbuftest.c | 139 ++------- tests/vircgrouptest.c | 2 - tests/virfirewalltest.c | 30 -- tests/virkmodtest.c | 6 +- tests/virnetdevbandwidthtest.c | 5 - tests/virsystemdtest.c | 3 - tests/viruritest.c | 2 +- tools/virsh-checkpoint.c | 5 - tools/virsh-domain-monitor.c | 6 - tools/virsh-domain.c | 30 -- tools/virsh-pool.c | 9 - tools/virsh-snapshot.c | 5 - tools/virsh-volume.c | 4 - tools/vsh.c | 33 +- tools/vsh.h | 5 +- 105 files changed, 224 insertions(+), 1264 deletions(-) -- 2.21.0

Spare a few more lines rather than having a condition with a nested ternary. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 04c8fd7291..a58481430a 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -64,11 +64,19 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) { if (!buf || buf->error) return; - if (indent > 0 ? INT_MAX - indent < buf->indent - : buf->indent < -indent) { - virBufferSetError(buf, -1); - return; + + if (indent > 0) { + if (INT_MAX - indent < buf->indent) { + virBufferSetError(buf, -1); + return; + } + } else { + if (buf->indent < -indent) { + virBufferSetError(buf, -1); + return; + } } + buf->indent += indent; } -- 2.21.0

On Thu, 2019-10-24 at 15:56 +0200, Peter Krempa wrote:
Spare a few more lines rather than having a condition with a nested ternary.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 04c8fd7291..a58481430a 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -64,11 +64,19 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) { if (!buf || buf->error) return; - if (indent > 0 ? INT_MAX - indent < buf->indent - : buf->indent < -indent) { - virBufferSetError(buf, -1); - return; + + if (indent > 0) { + if (INT_MAX - indent < buf->indent) { + virBufferSetError(buf, -1); + return; + } + } else { + if (buf->indent < -indent) { + virBufferSetError(buf, -1); + return; + } } + buf->indent += indent; }
It took me a few reads to make sure I understood the original code, so this is definitely an improvement. Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>

On Thu, Oct 24, 2019 at 03:56:19PM +0200, Peter Krempa wrote:
Spare a few more lines rather than having a condition with a nested ternary.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index a58481430a..a2b5aa8508 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -201,22 +201,22 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) return; if (!buf) - goto done; + goto cleanup; if (buf->error || toadd->error) { if (!buf->error) virBufferSetError(buf, toadd->error); - goto done; + goto cleanup; } if (virBufferGrow(buf, toadd->use) < 0) - goto done; + goto cleanup; memcpy(&buf->content[buf->use], toadd->content, toadd->use); buf->use += toadd->use; buf->content[buf->use] = '\0'; - done: + cleanup: virBufferFreeAndReset(toadd); } -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:20PM +0200, Peter Krempa wrote:
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Replace combinations of xalloc_oversized and VIR_ALLOC_N_QUIET by using g_malloc0_n which does the checking internally. This conversion is done with a semantic difference and slightly higher memory requirements as I've opted to allocate one chunk more than necessary rather than trying to accomodate the NUL byte separately. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index a2b5aa8508..bcf9042573 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -467,11 +467,7 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str) return; } - if (xalloc_oversized(6, len) || - VIR_ALLOC_N_QUIET(escaped, 6 * len + 1) < 0) { - virBufferSetError(buf, errno); - return; - } + escaped = g_malloc0_n(len + 1, 6); cur = str; out = escaped; @@ -616,11 +612,7 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, return; } - if (xalloc_oversized(2, len) || - VIR_ALLOC_N_QUIET(escaped, 2 * len + 1) < 0) { - virBufferSetError(buf, errno); - return; - } + escaped = g_malloc0_n(len + 1, 2); cur = str; out = escaped; @@ -715,11 +707,8 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if (*str) { len = strlen(str); - if (xalloc_oversized(4, len) || - VIR_ALLOC_N_QUIET(escaped, 4 * len + 3) < 0) { - virBufferSetError(buf, errno); - return; - } + + escaped = g_malloc0_n(len + 1, 4); } else { virBufferAddLit(buf, "''"); return; -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:21PM +0200, Peter Krempa wrote:
Replace combinations of xalloc_oversized and VIR_ALLOC_N_QUIET by using g_malloc0_n which does the checking internally.
This conversion is done with a semantic difference and slightly higher memory requirements as I've opted to allocate one chunk more than necessary rather than trying to accomodate the NUL byte separately.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Drop the dead code by using glib's allocator. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/vsh.c | 12 ++---------- tools/vsh.h | 5 +---- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index 3f8b7f2186..58ee94b52f 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -129,17 +129,9 @@ _vshMalloc(vshControl *ctl, size_t size, const char *filename, int line) } void * -_vshCalloc(vshControl *ctl, size_t nmemb, size_t size, const char *filename, - int line) +vshCalloc(vshControl *ctl G_GNUC_UNUSED, size_t nmemb, size_t size) { - char *x; - - if (!xalloc_oversized(nmemb, size) && - VIR_ALLOC_N(x, nmemb * size) == 0) - return x; - vshError(ctl, _("%s: %d: failed to allocate %d bytes"), - filename, line, (int) (size*nmemb)); - exit(EXIT_FAILURE); + return g_malloc0_n(nmemb, size); } int diff --git a/tools/vsh.h b/tools/vsh.h index ad783e24b7..b6ac070f10 100644 --- a/tools/vsh.h +++ b/tools/vsh.h @@ -468,10 +468,7 @@ char * vshReadline(vshControl *ctl, const char *prompt); void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line); #define vshMalloc(_ctl, _sz) _vshMalloc(_ctl, _sz, __FILE__, __LINE__) -void *_vshCalloc(vshControl *ctl, size_t nmemb, size_t sz, - const char *filename, int line); -#define vshCalloc(_ctl, _nmemb, _sz) \ - _vshCalloc(_ctl, _nmemb, _sz, __FILE__, __LINE__) +void *vshCalloc(vshControl *ctl, size_t nmemb, size_t sz); /* Macros to help dealing with mutually exclusive options. */ -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:22PM +0200, Peter Krempa wrote:
Drop the dead code by using glib's allocator.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tools/vsh.c | 12 ++---------- tools/vsh.h | 5 +---- 2 files changed, 3 insertions(+), 14 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

We'we now got rid of all the uses. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/viralloc.h | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/util/viralloc.h b/src/util/viralloc.h index d7862d6127..e6ad9984b7 100644 --- a/src/util/viralloc.h +++ b/src/util/viralloc.h @@ -33,25 +33,6 @@ * GLib array data types. See the hacking file for more guidance. */ -/* Return 1 if an array of N objects, each of size S, cannot exist due - to size arithmetic overflow. S must be positive and N must be - nonnegative. This is a macro, not an inline function, so that it - works correctly even when SIZE_MAX < N. - - By gnulib convention, SIZE_MAX represents overflow in size - calculations, so the conservative dividend to use here is - SIZE_MAX - 1, since SIZE_MAX might represent an overflowed value. - However, malloc (SIZE_MAX) fails on all known hosts where - sizeof(ptrdiff_t) <= sizeof(size_t), so do not bother to test for - exactly-SIZE_MAX allocations on such hosts; this avoids a test and - branch when S is known to be 1. */ -#ifndef xalloc_oversized -# define xalloc_oversized(n, s) \ - ((size_t) (sizeof(ptrdiff_t) <= sizeof(size_t) ? -1 : -2) / (s) < (n)) -#endif - - - /* Don't call these directly - use the macros below */ int virAlloc(void *ptrptr, size_t size) G_GNUC_WARN_UNUSED_RESULT ATTRIBUTE_NONNULL(1); -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:23PM +0200, Peter Krempa wrote:
We'we now got rid of all the uses.
s/we/ve/
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/viralloc.h | 19 ------------------- 1 file changed, 19 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Usage errors in the virBuffer are hard to track anyways. Just trim noting if the user requests the trimming string to be used without providing it. The change in the test proves that it's a noop now. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 6 +----- tests/virbuftest.c | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bcf9042573..9a74ca78bb 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -784,8 +784,6 @@ virBufferStrcat(virBufferPtr buf, ...) * if the current tail of the buffer matches @str; a non-negative @len * further limits how much of the tail is trimmed. If @str is NULL, then * @len must be non-negative. - * - * Sets error to -1 (usage) if str is NULL and len is less than zero. */ void virBufferTrim(virBufferPtr buf, const char *str, int len) @@ -794,10 +792,8 @@ virBufferTrim(virBufferPtr buf, const char *str, int len) if (!buf || buf->error) return; - if (!str && len < 0) { - virBufferSetError(buf, -1); + if (!str && len < 0) return; - } if (len > 0 && len > buf->use) return; diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 385f016174..8b8754adfa 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -163,6 +163,7 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) virBufferTrim(buf, "a", 2); virBufferAddLit(buf, ",b,,"); + virBufferTrim(buf, NULL, -1); virBufferTrim(buf, "b", -1); virBufferTrim(buf, "b,,", 1); virBufferTrim(buf, ",", -1); @@ -178,12 +179,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) goto cleanup; } - virBufferTrim(buf, NULL, -1); - if (virBufferError(buf) != -1) { - VIR_TEST_DEBUG("Usage error not flagged"); - goto cleanup; - } - ret = 0; cleanup: -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:24PM +0200, Peter Krempa wrote:
Usage errors in the virBuffer are hard to track anyways. Just trim noting if the user requests the trimming string to be used without providing it.
The change in the test proves that it's a noop now.
no-op
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 6 +----- tests/virbuftest.c | 7 +------ 2 files changed, 2 insertions(+), 11 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Rather than setting usage error truncate the indentation level. Having the output string misformated is way more useful to figure out where the error lies rather than reporting an error after a giant formatter function. In testBufAutoIndent we now validate that the indentation is truncated and testBufAddBuffer2 is removed since it became bogus. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 8 ++++---- tests/virbuftest.c | 35 ++++------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 9a74ca78bb..69fcf946f5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -56,8 +56,8 @@ virBufferSetError(virBufferPtr buf, int error) * negative to decrease). Automatic indentation is performed by all * additive functions when the existing buffer is empty or ends with a * newline (however, note that no indentation is added after newlines - * embedded in an appended string). If @indent would cause overflow, - * the buffer error indicator is set. + * embedded in an appended string). If @indent would cause overflow, the + * indentation level is truncated. */ void virBufferAdjustIndent(virBufferPtr buf, int indent) @@ -67,12 +67,12 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) if (indent > 0) { if (INT_MAX - indent < buf->indent) { - virBufferSetError(buf, -1); + buf->indent = INT_MAX; return; } } else { if (buf->indent < -indent) { - virBufferSetError(buf, -1); + buf->indent = 0; return; } } diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 8b8754adfa..246c572bd2 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -85,12 +85,12 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) ret = -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) != -1 || - virBufferGetIndent(buf, true) != -1 || - virBufferError(buf) != -1) { - VIR_TEST_DEBUG("Usage error not flagged"); + if (virBufferGetIndent(buf, false) != 0 || + virBufferGetIndent(buf, true) != 0) { + VIR_TEST_DEBUG("Indentation level not truncated"); ret = -1; } + virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf, false) != 0 || virBufferGetIndent(buf, true) != 0 || @@ -298,32 +298,6 @@ static int testBufAddBuffer(const void *data G_GNUC_UNUSED) return ret; } -static int -testBufAddBuffer2(const void *opaque G_GNUC_UNUSED) -{ - g_auto(virBuffer) buf1 = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) buf2 = VIR_BUFFER_INITIALIZER; - - /* Intent of this test is to demonstrate a memleak that happen with - * virBufferAddBuffer */ - - virBufferAddLit(&buf1, "Hello world!\n"); - virBufferAddLit(&buf2, "Hello world!\n"); - - /* Intentional usage error */ - virBufferAdjustIndent(&buf2, -2); - - virBufferAddBuffer(&buf1, &buf2); - - if (virBufferCurrentContent(&buf1) || - !virBufferCurrentContent(&buf2)) { - VIR_TEST_DEBUG("Unexpected buffer content"); - return -1; - } - - return 0; -} - struct testBufAddStrData { const char *data; const char *expect; @@ -481,7 +455,6 @@ mymain(void) DO_TEST("Auto-indentation", testBufAutoIndent, 0); DO_TEST("Trim", testBufTrim, 0); DO_TEST("AddBuffer", testBufAddBuffer, 0); - DO_TEST("AddBuffer2", testBufAddBuffer2, 0); DO_TEST("set indent", testBufSetIndent, 0); DO_TEST("autoclean", testBufferAutoclean, 0); -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:25PM +0200, Peter Krempa wrote:
Rather than setting usage error truncate the indentation level. Having the output string misformated is way more useful to figure out where the error lies rather than reporting an error after a giant formatter function.
In testBufAutoIndent we now validate that the indentation is truncated and testBufAddBuffer2 is removed since it became bogus.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 8 ++++---- tests/virbuftest.c | 35 ++++------------------------------- 2 files changed, 8 insertions(+), 35 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The tests are deeply based on internals of virBuffer which will be replaced in an upcoming patch with glib's GString. Remove the tests. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virbuftest.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-) diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 246c572bd2..21b6295bb3 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -13,45 +13,6 @@ struct testInfo { int doEscape; }; -static int testBufInfiniteLoop(const void *data) -{ - virBuffer bufinit = VIR_BUFFER_INITIALIZER; - virBufferPtr buf = &bufinit; - char *addstr = NULL, *bufret = NULL; - int ret = -1; - const struct testInfo *info = data; - int len; - - virBufferAddChar(buf, 'a'); - - /* - * Infinite loop used to trigger if: - * (strlen + 1 > 1000) && (strlen == buf-size - buf-use - 1) - * which was the case after the above addchar at the time of the bug. - * This test is a bit fragile, since it relies on virBuffer internals. - */ - len = buf->size - buf->use - 1; - if (virAsprintf(&addstr, "%*s", len, "a") < 0) - goto out; - - if (info->doEscape) - virBufferEscapeString(buf, "%s", addstr); - else - virBufferAsprintf(buf, "%s", addstr); - - ret = 0; - out: - bufret = virBufferContentAndReset(buf); - if (!bufret) { - VIR_TEST_DEBUG("Buffer had error set"); - ret = -1; - } - - VIR_FREE(addstr); - VIR_FREE(bufret); - return ret; -} - static int testBufAutoIndent(const void *data G_GNUC_UNUSED) { virBuffer bufinit = VIR_BUFFER_INITIALIZER; @@ -450,8 +411,6 @@ mymain(void) ret = -1; \ } while (0) - DO_TEST("EscapeString infinite loop", testBufInfiniteLoop, 1); - DO_TEST("VSprintf infinite loop", testBufInfiniteLoop, 0); DO_TEST("Auto-indentation", testBufAutoIndent, 0); DO_TEST("Trim", testBufTrim, 0); DO_TEST("AddBuffer", testBufAddBuffer, 0); -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:26PM +0200, Peter Krempa wrote:
The tests are deeply based on internals of virBuffer which will be replaced in an upcoming patch with glib's GString. Remove the tests.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virbuftest.c | 41 ----------------------------------------- 1 file changed, 41 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The DO_TEST macro initializes 'struct testInfo' but it's not used by any of the tests. Remove it. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virbuftest.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 21b6295bb3..064b3e96b4 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -9,10 +9,6 @@ #define VIR_FROM_THIS VIR_FROM_NONE -struct testInfo { - int doEscape; -}; - static int testBufAutoIndent(const void *data G_GNUC_UNUSED) { virBuffer bufinit = VIR_BUFFER_INITIALIZER; @@ -404,18 +400,17 @@ mymain(void) int ret = 0; -#define DO_TEST(msg, cb, data) \ +#define DO_TEST(msg, cb) \ do { \ - struct testInfo info = { data }; \ - if (virTestRun("Buf: " msg, cb, &info) < 0) \ + if (virTestRun("Buf: " msg, cb, NULL) < 0) \ ret = -1; \ } while (0) - DO_TEST("Auto-indentation", testBufAutoIndent, 0); - DO_TEST("Trim", testBufTrim, 0); - DO_TEST("AddBuffer", testBufAddBuffer, 0); - DO_TEST("set indent", testBufSetIndent, 0); - DO_TEST("autoclean", testBufferAutoclean, 0); + DO_TEST("Auto-indentation", testBufAutoIndent); + DO_TEST("Trim", testBufTrim); + DO_TEST("AddBuffer", testBufAddBuffer); + DO_TEST("set indent", testBufSetIndent); + DO_TEST("autoclean", testBufferAutoclean); #define DO_TEST_ADD_STR(DATA, EXPECT) \ do { \ -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:27PM +0200, Peter Krempa wrote:
The DO_TEST macro initializes 'struct testInfo' but it's not used by any of the tests. Remove it.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/virbuftest.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The function basically does two very distinct things depending on a bool. As a first step of conversion split out the case when @dynamic is true and implement it as a new function and convert all callers. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virbuffer.c | 26 +++++++++++++++++++++----- src/util/virbuffer.h | 1 + tests/virbuftest.c | 12 ++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 12cb3b5bf7..94c2e4ef6a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1600,6 +1600,7 @@ virBufferEscapeShell; virBufferEscapeSQL; virBufferEscapeString; virBufferFreeAndReset; +virBufferGetEffectiveIndent; virBufferGetIndent; virBufferSetIndent; virBufferStrcat; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 69fcf946f5..0d2721b118 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -117,6 +117,24 @@ virBufferGetIndent(const virBuffer *buf, bool dynamic) return buf->indent; } + +/** + * virBufferGetEffectiveIndent: + * @buf: the buffer + * + * Returns the number of spaces that need to be appended to @buf to honour + * auto-indentation. + */ +size_t +virBufferGetEffectiveIndent(const virBuffer *buf) +{ + if (buf->use && buf->content[buf->use - 1] != '\n') + return 0; + + return buf->indent; +} + + /** * virBufferGrow: * @buf: the buffer @@ -161,14 +179,12 @@ void virBufferAdd(virBufferPtr buf, const char *str, int len) { unsigned int needSize; - int indent; + size_t indent; - if (!str || !buf || (len == 0 && buf->indent == 0)) + if (!str || !buf || buf->error || (len == 0 && buf->indent == 0)) return; - indent = virBufferGetIndent(buf, true); - if (indent < 0) - return; + indent = virBufferGetEffectiveIndent(buf); if (len < 0) len = strlen(str); diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index ff24ab1019..7156d9d0d8 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -110,6 +110,7 @@ void virBufferSetIndent(virBufferPtr, int indent); virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2) int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); void virBufferAddStr(virBufferPtr buf, const char *str); diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 064b3e96b4..0c806908e1 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -19,7 +19,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) int ret = 0; if (virBufferGetIndent(buf, false) != 0 || - virBufferGetIndent(buf, true) != 0) { + virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } @@ -29,28 +29,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) ret = -1; } if (virBufferGetIndent(buf, false) != 3 || - virBufferGetIndent(buf, true) != 3 || + virBufferGetEffectiveIndent(buf) != 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -2); if (virBufferGetIndent(buf, false) != 1 || - virBufferGetIndent(buf, true) != 1 || + virBufferGetEffectiveIndent(buf) != 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -3); if (virBufferGetIndent(buf, false) != 0 || - virBufferGetIndent(buf, true) != 0) { + virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret = -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf, false) != 0 || - virBufferGetIndent(buf, true) != 0 || + virBufferGetEffectiveIndent(buf) != 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); ret = -1; @@ -66,7 +66,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) ret = -1; } if (virBufferGetIndent(buf, false) != 2 || - virBufferGetIndent(buf, true) != 0) { + virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:28PM +0200, Peter Krempa wrote:
The function basically does two very distinct things depending on a bool. As a first step of conversion split out the case when @dynamic is true and implement it as a new function and convert all callers.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/libvirt_private.syms | 1 + src/util/virbuffer.c | 26 +++++++++++++++++++++----- src/util/virbuffer.h | 1 + tests/virbuftest.c | 12 ++++++------ 4 files changed, 29 insertions(+), 11 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

It basically implements almost the same thing, so we can replace it with existing helpers with a few tweaks. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virsysinfo.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0a622dbbf9..6e7e221f00 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -1481,20 +1481,19 @@ virSysinfoOEMStringsFormat(virBufferPtr buf, virSysinfoOEMStringsDefPtr def) int virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) { + virBuffer attrBuf = VIR_BUFFER_INITIALIZER; virBuffer childrenBuf = VIR_BUFFER_INITIALIZER; const char *type = virSysinfoTypeToString(def->type); - int indent = virBufferGetIndent(buf, false); - int ret = -1; if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected sysinfo type model %d"), def->type); virBufferFreeAndReset(buf); - goto cleanup; + return -1; } - virBufferAdjustIndent(&childrenBuf, indent + 2); + virBufferSetChildIndent(&childrenBuf, buf); virSysinfoBIOSFormat(&childrenBuf, def->bios); virSysinfoSystemFormat(&childrenBuf, def->system); @@ -1504,22 +1503,17 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) virSysinfoMemoryFormat(&childrenBuf, def); virSysinfoOEMStringsFormat(&childrenBuf, def->oemStrings); - virBufferAsprintf(buf, "<sysinfo type='%s'", type); - if (virBufferUse(&childrenBuf)) { - virBufferAddLit(buf, ">\n"); - virBufferAddBuffer(buf, &childrenBuf); - virBufferAddLit(buf, "</sysinfo>\n"); - } else { - virBufferAddLit(buf, "/>\n"); + virBufferAsprintf(&attrBuf, " type='%s'", type); + + if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) { + virBufferFreeAndReset(buf); + return -1; } if (virBufferCheckError(buf) < 0) - goto cleanup; + return -1; - ret = 0; - cleanup: - virBufferFreeAndReset(&childrenBuf); - return ret; + return 0; } #define CHECK_FIELD(name, desc) \ -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:29PM +0200, Peter Krempa wrote:
It basically implements almost the same thing, so we can replace it with existing helpers with a few tweaks.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virsysinfo.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

After the conversion of all callers that would pass true as @dynamic to a different function we can remove the unused argument now. Additionally modify the return type to 'size_t' as indentation can't be negative and remove checks whether @buf is passed as it's caller's duty to do so. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 2 +- src/conf/network_conf.c | 2 +- src/util/virbuffer.c | 12 +++--------- src/util/virbuffer.h | 4 ++-- tests/testutilsqemuschema.c | 2 +- tests/virbuftest.c | 12 ++++++------ 6 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9ee9b44a5e..81006119aa 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28493,7 +28493,7 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 7f8e43b25c..1d20d28f46 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2458,7 +2458,7 @@ virNetworkDefFormatBuf(virBufferPtr buf, xmlIndentTreeOutput = 1; xmlbuf = xmlBufferCreate(); if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata, - virBufferGetIndent(buf, false) / 2, 1) < 0) { + virBufferGetIndent(buf) / 2, 1) < 0) { xmlBufferFree(xmlbuf); xmlIndentTreeOutput = oldIndentTreeOutput; goto error; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 0d2721b118..bf703fe7a5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -102,18 +102,12 @@ virBufferSetIndent(virBufferPtr buf, int indent) /** * virBufferGetIndent: * @buf: the buffer - * @dynamic: if false, return set value; if true, return 0 unless next - * append would be affected by auto-indent * - * Return the current auto-indent value, or -1 if there has been an error. + * Return the current auto-indent setting of @buf. */ -int -virBufferGetIndent(const virBuffer *buf, bool dynamic) +size_t +virBufferGetIndent(const virBuffer *buf) { - if (!buf || buf->error) - return -1; - if (dynamic && buf->use && buf->content[buf->use - 1] != '\n') - return 0; return buf->indent; } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 7156d9d0d8..6c41a7ea20 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -107,9 +107,9 @@ void virBufferSetIndent(virBufferPtr, int indent); * child buffer. */ #define virBufferSetChildIndent(childBuf_, parentBuf_) \ - virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_, false) + 2) + virBufferSetIndent(childBuf_, virBufferGetIndent(parentBuf_) + 2) -int virBufferGetIndent(const virBuffer *buf, bool dynamic); +size_t virBufferGetIndent(const virBuffer *buf); size_t virBufferGetEffectiveIndent(const virBuffer *buf); void virBufferTrim(virBufferPtr buf, const char *trim, int len); diff --git a/tests/testutilsqemuschema.c b/tests/testutilsqemuschema.c index 42b2550a03..9a1b1fea07 100644 --- a/tests/testutilsqemuschema.c +++ b/tests/testutilsqemuschema.c @@ -430,7 +430,7 @@ testQEMUSchemaValidateAlternate(virJSONValuePtr obj, virBufferAddLit(debug, "(\n"); virBufferAdjustIndent(debug, 3); - indent = virBufferGetIndent(debug, false); + indent = virBufferGetIndent(debug); n = virJSONValueArraySize(members); for (i = 0; i < n; i++) { diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 0c806908e1..34aa8b678b 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -18,7 +18,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) char *result = NULL; int ret = 0; - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; @@ -28,28 +28,28 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 3 || + if (virBufferGetIndent(buf) != 3 || virBufferGetEffectiveIndent(buf) != 3 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -2); - if (virBufferGetIndent(buf, false) != 1 || + if (virBufferGetIndent(buf) != 1 || virBufferGetEffectiveIndent(buf) != 1 || virBufferError(buf)) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -3); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Indentation level not truncated"); ret = -1; } virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); - if (virBufferGetIndent(buf, false) != 0 || + if (virBufferGetIndent(buf) != 0 || virBufferGetEffectiveIndent(buf) != 0 || virBufferError(buf)) { VIR_TEST_DEBUG("Reset didn't clear indentation"); @@ -65,7 +65,7 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) VIR_TEST_DEBUG("Wrong content"); ret = -1; } - if (virBufferGetIndent(buf, false) != 2 || + if (virBufferGetIndent(buf) != 2 || virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:30PM +0200, Peter Krempa wrote:
After the conversion of all callers that would pass true as @dynamic to a different function we can remove the unused argument now.
Additionally modify the return type to 'size_t' as indentation can't be negative and remove checks whether @buf is passed as it's caller's duty to do so.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 2 +- src/conf/network_conf.c | 2 +- src/util/virbuffer.c | 12 +++--------- src/util/virbuffer.h | 4 ++-- tests/testutilsqemuschema.c | 2 +- tests/virbuftest.c | 12 ++++++------ 6 files changed, 14 insertions(+), 20 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

According to rfc3986: 2.3. Unreserved Characters Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde. unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers. Thus we must not include few other characters which don't match c_isalpha to conform to the rules. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 14 ++++++++++++-- tests/viruritest.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bf703fe7a5..bde118a248 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -638,6 +638,16 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, } +static bool +virBufferURIEncodeCharIsUnencoded(char c) +{ + if (c == '-' || c == '.' || c == '_' || c == '~') + return true; + + return c_isalnum(c); +} + + /** * virBufferURIEncodeString: * @buf: the buffer to append to @@ -664,7 +674,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str) virBufferAddLit(buf, ""); /* auto-indent */ for (p = str; *p; ++p) { - if (c_isalnum(*p)) + if (virBufferURIEncodeCharIsUnencoded(*p)) grow_size++; else grow_size += 3; /* %ab */ @@ -674,7 +684,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str) return; for (p = str; *p; ++p) { - if (c_isalnum(*p)) { + if (virBufferURIEncodeCharIsUnencoded(*p)) { buf->content[buf->use++] = *p; } else { uc = (unsigned char) *p; diff --git a/tests/viruritest.c b/tests/viruritest.c index 3255e2333a..a11587e52b 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -184,7 +184,7 @@ mymain(void) { NULL, NULL, false }, }; TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", - "spice://[3ffe::104]:5900/?tlsSubject=C%3dXX%2cL%3dTesttown%2cO%3dTest%20Company%2cCN%3dtester%2etest", + "spice://[3ffe::104]:5900/?tlsSubject=C%3dXX%2cL%3dTesttown%2cO%3dTest%20Company%2cCN%3dtester.test", "spice", "3ffe::104", 5900, "/", "tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", NULL, NULL, spiceparams); virURIParam params1[] = { -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:31PM +0200, Peter Krempa wrote:
According to rfc3986:
Ah, it's been a while since I read that.
2.3. Unreserved Characters
Characters that are allowed in a URI but do not have a reserved purpose are called unreserved. These include uppercase and lowercase letters, decimal digits, hyphen, period, underscore, and tilde.
unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
URIs that differ in the replacement of an unreserved character with its corresponding percent-encoded US-ASCII octet are equivalent: they identify the same resource. However, URI comparison implementations do not always perform normalization prior to comparison (see Section 6). For consistency, percent-encoded octets in the ranges of ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D), period (%2E), underscore (%5F), or tilde (%7E) should not be created by URI producers and, when found in a URI, should be decoded to their corresponding unreserved characters by URI normalizers.
Thus we must not include few other characters which don't match c_isalpha to conform to the rules.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 14 ++++++++++++-- tests/viruritest.c | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

rfc3986 uses uppercase characters so switch to using them as well. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 2 +- tests/viruritest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index bde118a248..2256bd5de5 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -663,7 +663,7 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str) int grow_size = 0; const char *p; unsigned char uc; - const char *hex = "0123456789abcdef"; + const char *hex = "0123456789ABCDEF"; if ((buf == NULL) || (str == NULL)) return; diff --git a/tests/viruritest.c b/tests/viruritest.c index a11587e52b..07cf7261d1 100644 --- a/tests/viruritest.c +++ b/tests/viruritest.c @@ -184,7 +184,7 @@ mymain(void) { NULL, NULL, false }, }; TEST_FULL("spice://[3ffe::104]:5900/?tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", - "spice://[3ffe::104]:5900/?tlsSubject=C%3dXX%2cL%3dTesttown%2cO%3dTest%20Company%2cCN%3dtester.test", + "spice://[3ffe::104]:5900/?tlsSubject=C%3DXX%2CL%3DTesttown%2CO%3DTest%20Company%2CCN%3Dtester.test", "spice", "3ffe::104", 5900, "/", "tlsSubject=C=XX,L=Testtown,O=Test%20Company,CN=tester.test", NULL, NULL, spiceparams); virURIParam params1[] = { -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:32PM +0200, Peter Krempa wrote:
rfc3986 uses uppercase characters so switch to using them as well.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 2 +- tests/viruritest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

GString is surprisingly similar to what libvirt was doing painstaikingly manually. Yet it doesn't support the automatic indentation features we use for XML so we rather keep those in form of virBuffer using GString internally. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 205 +++++++++++++++---------------------------- src/util/virbuffer.h | 6 +- 2 files changed, 71 insertions(+), 140 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 2256bd5de5..9306b79703 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -21,7 +21,6 @@ #include <config.h> #include <stdarg.h> -#include "c-ctype.h" #include "virbuffer.h" #include "virerror.h" @@ -40,10 +39,7 @@ static void virBufferSetError(virBufferPtr buf, int error) { - VIR_FREE(buf->content); - buf->size = 0; - buf->use = 0; - buf->indent = 0; + virBufferFreeAndReset(buf); buf->error = error; } @@ -122,7 +118,7 @@ virBufferGetIndent(const virBuffer *buf) size_t virBufferGetEffectiveIndent(const virBuffer *buf) { - if (buf->use && buf->content[buf->use - 1] != '\n') + if (buf->str && buf->str->len && buf->str->str[buf->str->len - 1] != '\n') return 0; return buf->indent; @@ -130,35 +126,38 @@ virBufferGetEffectiveIndent(const virBuffer *buf) /** - * virBufferGrow: + * virBufferInitialize * @buf: the buffer - * @len: the minimum free size to allocate on top of existing used space * - * Grow the available space of a buffer to at least @len bytes. - * - * Returns zero on success or -1 on error + * Ensures that the internal GString container is allocated. */ -static int -virBufferGrow(virBufferPtr buf, unsigned int len) +static void +virBufferInitialize(virBufferPtr buf) { - int size; + if (!buf->str) + buf->str = g_string_new(NULL); +} - if (buf->error) - return -1; - if ((len + buf->use) < buf->size) - return 0; +static void +virBufferApplyIndent(virBufferPtr buf) +{ + const char space[] = " "; + size_t spacesz = sizeof(space) - 1; + size_t toindent = virBufferGetEffectiveIndent(buf); - size = buf->use + len + 1000; + if (toindent == 0) + return; - if (VIR_REALLOC_N_QUIET(buf->content, size) < 0) { - virBufferSetError(buf, errno); - return -1; + while (toindent > spacesz) { + g_string_append_len(buf->str, space, spacesz); + toindent -= spacesz; } - buf->size = size; - return 0; + + g_string_append_len(buf->str, space, toindent); } + /** * virBufferAdd: * @buf: the buffer to append to @@ -172,25 +171,16 @@ virBufferGrow(virBufferPtr buf, unsigned int len) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - unsigned int needSize; - size_t indent; - if (!str || !buf || buf->error || (len == 0 && buf->indent == 0)) return; - indent = virBufferGetEffectiveIndent(buf); + virBufferInitialize(buf); + virBufferApplyIndent(buf); if (len < 0) - len = strlen(str); - - needSize = buf->use + indent + len + 2; - if (virBufferGrow(buf, needSize - buf->use) < 0) - return; - - memset(&buf->content[buf->use], ' ', indent); - memcpy(&buf->content[buf->use + indent], str, len); - buf->use += indent + len; - buf->content[buf->use] = '\0'; + g_string_append(buf->str, str); + else + g_string_append_len(buf->str, str, len); } /** @@ -207,7 +197,7 @@ virBufferAdd(virBufferPtr buf, const char *str, int len) void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) { - if (!toadd) + if (!toadd || !toadd->str) return; if (!buf) @@ -219,12 +209,8 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) goto cleanup; } - if (virBufferGrow(buf, toadd->use) < 0) - goto cleanup; - - memcpy(&buf->content[buf->use], toadd->content, toadd->use); - buf->use += toadd->use; - buf->content[buf->use] = '\0'; + virBufferInitialize(buf); + g_string_append_len(buf->str, toadd->str->str, toadd->str->len); cleanup: virBufferFreeAndReset(toadd); @@ -259,7 +245,12 @@ virBufferCurrentContent(virBufferPtr buf) { if (!buf || buf->error) return NULL; - return buf->use ? buf->content : ""; + + if (!buf->str || + buf->str->len == 0) + return ""; + + return buf->str->str; } /** @@ -277,16 +268,14 @@ virBufferCurrentContent(virBufferPtr buf) char * virBufferContentAndReset(virBufferPtr buf) { - char *str; - if (buf == NULL) - return NULL; + char *str = NULL; - if (buf->error) { - memset(buf, 0, sizeof(*buf)); + if (!buf) return NULL; - } - str = buf->content; + if (buf->str) + str = g_string_free(buf->str, false); + memset(buf, 0, sizeof(*buf)); return str; } @@ -299,8 +288,13 @@ virBufferContentAndReset(virBufferPtr buf) */ void virBufferFreeAndReset(virBufferPtr buf) { - if (buf) - virBufferSetError(buf, 0); + if (!buf) + return; + + if (buf->str) + g_string_free(buf->str, true); + + memset(buf, 0, sizeof(*buf)); } /** @@ -360,10 +354,10 @@ virBufferCheckErrorInternal(const virBuffer *buf, size_t virBufferUse(const virBuffer *buf) { - if (buf == NULL) + if (!buf || !buf->str) return 0; - return buf->use; + return buf->str->len; } /** @@ -394,48 +388,16 @@ virBufferAsprintf(virBufferPtr buf, const char *format, ...) void virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr) { - int size, count, grow_size; - va_list copy; - if ((format == NULL) || (buf == NULL)) return; if (buf->error) return; - virBufferAddLit(buf, ""); /* auto-indent */ + virBufferInitialize(buf); + virBufferApplyIndent(buf); - if (buf->size == 0 && - virBufferGrow(buf, 100) < 0) - return; - - va_copy(copy, argptr); - - size = buf->size - buf->use; - if ((count = vsnprintf(&buf->content[buf->use], - size, format, copy)) < 0) { - virBufferSetError(buf, errno); - va_end(copy); - return; - } - va_end(copy); - - /* Grow buffer if necessary and retry */ - if (count >= size) { - buf->content[buf->use] = 0; - - grow_size = (count + 1 > 1000) ? count + 1 : 1000; - if (virBufferGrow(buf, grow_size) < 0) - return; - - size = buf->size - buf->use; - if ((count = vsnprintf(&buf->content[buf->use], - size, format, argptr)) < 0) { - virBufferSetError(buf, errno); - return; - } - } - buf->use += count; + g_string_append_vprintf(buf->str, format, argptr); } @@ -638,16 +600,6 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, } -static bool -virBufferURIEncodeCharIsUnencoded(char c) -{ - if (c == '-' || c == '.' || c == '_' || c == '~') - return true; - - return c_isalnum(c); -} - - /** * virBufferURIEncodeString: * @buf: the buffer to append to @@ -660,41 +612,16 @@ virBufferURIEncodeCharIsUnencoded(char c) void virBufferURIEncodeString(virBufferPtr buf, const char *str) { - int grow_size = 0; - const char *p; - unsigned char uc; - const char *hex = "0123456789ABCDEF"; - if ((buf == NULL) || (str == NULL)) return; if (buf->error) return; - virBufferAddLit(buf, ""); /* auto-indent */ - - for (p = str; *p; ++p) { - if (virBufferURIEncodeCharIsUnencoded(*p)) - grow_size++; - else - grow_size += 3; /* %ab */ - } - - if (virBufferGrow(buf, grow_size) < 0) - return; - - for (p = str; *p; ++p) { - if (virBufferURIEncodeCharIsUnencoded(*p)) { - buf->content[buf->use++] = *p; - } else { - uc = (unsigned char) *p; - buf->content[buf->use++] = '%'; - buf->content[buf->use++] = hex[uc >> 4]; - buf->content[buf->use++] = hex[uc & 0xf]; - } - } + virBufferInitialize(buf); + virBufferApplyIndent(buf); - buf->content[buf->use] = '\0'; + g_string_append_uri_escaped(buf->str, str, NULL, false); } /** @@ -810,21 +737,27 @@ virBufferTrim(virBufferPtr buf, const char *str, int len) { size_t len2 = 0; - if (!buf || buf->error) + if (!buf || buf->error || !buf->str) return; + if (!str && len < 0) return; - if (len > 0 && len > buf->use) + + if (len > 0 && len > buf->str->len) return; + if (str) { len2 = strlen(str); - if (len2 > buf->use || - memcmp(&buf->content[buf->use - len2], str, len2) != 0) + if (len2 > buf->str->len || + memcmp(&buf->str->str[buf->str->len - len2], str, len2) != 0) return; } - buf->use -= len < 0 ? len2 : len; - buf->content[buf->use] = '\0'; + + if (len < 0) + len = len2; + + g_string_truncate(buf->str, buf->str->len - len); } diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 6c41a7ea20..f5b3961f9b 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -33,14 +33,12 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -#define VIR_BUFFER_INITIALIZER { 0, 0, 0, 0, NULL } +#define VIR_BUFFER_INITIALIZER { NULL, 0, 0 } struct _virBuffer { - size_t size; - size_t use; + GString *str; int error; /* errno value, or -1 for usage error */ int indent; - char *content; }; const char *virBufferCurrentContent(virBufferPtr buf); -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:33PM +0200, Peter Krempa wrote:
GString is surprisingly similar to what libvirt was doing painstaikingly
painstakingly Imagine a pancake, but much more convoluted.
manually. Yet it doesn't support the automatic indentation features we use for XML so we rather keep those in form of virBuffer using GString internally.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 205 +++++++++++++++---------------------------- src/util/virbuffer.h | 6 +- 2 files changed, 71 insertions(+), 140 deletions(-)
diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 2256bd5de5..9306b79703 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c +static void +virBufferApplyIndent(virBufferPtr buf) +{ + const char space[] = " "; + size_t spacesz = sizeof(space) - 1;
/* infinity minus one */
+ size_t toindent = virBufferGetEffectiveIndent(buf);
- size = buf->use + len + 1000; + if (toindent == 0) + return;
@@ -810,21 +737,27 @@ virBufferTrim(virBufferPtr buf, const char *str, int len) { size_t len2 = 0;
- if (!buf || buf->error) + if (!buf || buf->error || !buf->str) return; + if (!str && len < 0) return;
- if (len > 0 && len > buf->use) + + if (len > 0 && len > buf->str->len) return; + if (str) { len2 = strlen(str); - if (len2 > buf->use || - memcmp(&buf->content[buf->use - len2], str, len2) != 0) + if (len2 > buf->str->len || + memcmp(&buf->str->str[buf->str->len - len2], str, len2) != 0) return; } - buf->use -= len < 0 ? len2 : len; - buf->content[buf->use] = '\0'; + + if (len < 0) + len = len2;
This function is odd. Maybe it would work better as two (which is - ironically - even) separate ones. But the conversion looks good.
+ + g_string_truncate(buf->str, buf->str->len - len); }
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Now that there are no errors reported and tracked in virBuffer, remove all the internals which were used to track them. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 78 ++++++-------------------------------------- src/util/virbuffer.h | 13 +++----- 2 files changed, 14 insertions(+), 77 deletions(-) diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index 9306b79703..e6480ca4ef 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -23,26 +23,11 @@ #include <stdarg.h> #include "virbuffer.h" -#include "virerror.h" #include "virstring.h" #include "viralloc.h" #define VIR_FROM_THIS VIR_FROM_NONE -/** - * virBufferFail - * @buf: the buffer - * @error: which error occurred (errno value, or -1 for usage) - * - * Mark the buffer as failed, free the content and set the error flag. - */ -static void -virBufferSetError(virBufferPtr buf, int error) -{ - virBufferFreeAndReset(buf); - buf->error = error; -} - /** * virBufferAdjustIndent: * @buf: the buffer @@ -58,7 +43,7 @@ virBufferSetError(virBufferPtr buf, int error) void virBufferAdjustIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; if (indent > 0) { @@ -88,7 +73,7 @@ virBufferAdjustIndent(virBufferPtr buf, int indent) void virBufferSetIndent(virBufferPtr buf, int indent) { - if (!buf || buf->error) + if (!buf) return; buf->indent = indent; @@ -171,7 +156,7 @@ virBufferApplyIndent(virBufferPtr buf) void virBufferAdd(virBufferPtr buf, const char *str, int len) { - if (!str || !buf || buf->error || (len == 0 && buf->indent == 0)) + if (!str || !buf || (len == 0 && buf->indent == 0)) return; virBufferInitialize(buf); @@ -203,12 +188,6 @@ virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd) if (!buf) goto cleanup; - if (buf->error || toadd->error) { - if (!buf->error) - virBufferSetError(buf, toadd->error); - goto cleanup; - } - virBufferInitialize(buf); g_string_append_len(buf->str, toadd->str->str, toadd->str->len); @@ -243,7 +222,7 @@ virBufferAddChar(virBufferPtr buf, char c) const char * virBufferCurrentContent(virBufferPtr buf) { - if (!buf || buf->error) + if (!buf) return NULL; if (!buf->str || @@ -307,12 +286,9 @@ void virBufferFreeAndReset(virBufferPtr buf) * Return positive errno value or -1 on usage error, 0 if normal */ int -virBufferError(const virBuffer *buf) +virBufferError(const virBuffer *buf G_GNUC_UNUSED) { - if (buf == NULL) - return -1; - - return buf->error; + return 0; } /** @@ -324,25 +300,9 @@ virBufferError(const virBuffer *buf) * Return -1 if an error has been reported, 0 otherwise. */ int -virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +virBufferCheckErrorInternal(const virBuffer *buf G_GNUC_UNUSED) { - if (buf->error == 0) - return 0; - - if (buf->error == ENOMEM) { - virReportOOMErrorFull(domcode, filename, funcname, linenr); - errno = ENOMEM; - } else { - virReportErrorHelper(domcode, VIR_ERR_INTERNAL_ERROR, filename, - funcname, linenr, "%s", - _("Invalid buffer API usage")); - errno = EINVAL; - } - return -1; + return 0; } /** @@ -391,9 +351,6 @@ virBufferVasprintf(virBufferPtr buf, const char *format, va_list argptr) if ((format == NULL) || (buf == NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -430,9 +387,6 @@ virBufferEscapeString(virBufferPtr buf, const char *format, const char *str) if ((format == NULL) || (buf == NULL) || (str == NULL)) return; - if (buf->error) - return; - len = strlen(str); if (strcspn(str, forbidden_characters) == len) { virBufferAsprintf(buf, format, str); @@ -575,9 +529,6 @@ virBufferEscape(virBufferPtr buf, char escape, const char *toescape, if ((format == NULL) || (buf == NULL) || (str == NULL)) return; - if (buf->error) - return; - len = strlen(str); if (strcspn(str, toescape) == len) { virBufferAsprintf(buf, format, str); @@ -615,9 +566,6 @@ virBufferURIEncodeString(virBufferPtr buf, const char *str) if ((buf == NULL) || (str == NULL)) return; - if (buf->error) - return; - virBufferInitialize(buf); virBufferApplyIndent(buf); @@ -643,9 +591,6 @@ virBufferEscapeShell(virBufferPtr buf, const char *str) if ((buf == NULL) || (str == NULL)) return; - if (buf->error) - return; - /* Only quote if str includes shell metacharacters. */ if (*str && !strpbrk(str, "\r\t\n !\"#$&'()*;<>?[\\]^`{|}~")) { virBufferAdd(buf, str, -1); @@ -693,9 +638,6 @@ virBufferStrcatVArgs(virBufferPtr buf, { char *str; - if (buf->error) - return; - while ((str = va_arg(ap, char *)) != NULL) virBufferAdd(buf, str, -1); } @@ -737,7 +679,7 @@ virBufferTrim(virBufferPtr buf, const char *str, int len) { size_t len2 = 0; - if (!buf || buf->error || !buf->str) + if (!buf || !buf->str) return; if (!str && len < 0) @@ -775,7 +717,7 @@ virBufferAddStr(virBufferPtr buf, { const char *end; - if (!buf || !str || buf->error) + if (!buf || !str) return; while (*str) { diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index f5b3961f9b..9adec89f57 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -33,11 +33,10 @@ typedef struct _virBuffer virBuffer; typedef virBuffer *virBufferPtr; -#define VIR_BUFFER_INITIALIZER { NULL, 0, 0 } +#define VIR_BUFFER_INITIALIZER { NULL, 0 } struct _virBuffer { GString *str; - int error; /* errno value, or -1 for usage error */ int indent; }; @@ -45,11 +44,7 @@ const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); int virBufferError(const virBuffer *buf); -int virBufferCheckErrorInternal(const virBuffer *buf, - int domcode, - const char *filename, - const char *funcname, - size_t linenr) +int virBufferCheckErrorInternal(const virBuffer *buf) ATTRIBUTE_NONNULL(1); G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset); @@ -63,8 +58,8 @@ G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset); * and -1 is returned. */ #define virBufferCheckError(buf) \ - virBufferCheckErrorInternal(buf, VIR_FROM_THIS, __FILE__, __FUNCTION__, \ - __LINE__) + virBufferCheckErrorInternal(buf) + size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:34PM +0200, Peter Krempa wrote:
Now that there are no errors reported and tracked in virBuffer, remove all the internals which were used to track them.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/util/virbuffer.c | 78 ++++++-------------------------------------- src/util/virbuffer.h | 13 +++----- 2 files changed, 14 insertions(+), 77 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The function now never returned an error so we can drop it fully. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 2 -- src/libvirt_private.syms | 1 - src/nwfilter/nwfilter_gentech_driver.c | 4 ---- src/nwfilter/nwfilter_learnipaddr.c | 5 ----- src/security/virt-aa-helper.c | 11 ---------- src/util/virbitmap.c | 6 ------ src/util/virbuffer.c | 15 ------------- src/util/virbuffer.h | 1 - src/util/vircommand.c | 8 +------ src/util/virlog.c | 8 ------- tests/cputest.c | 4 ---- tests/networkxml2firewalltest.c | 3 --- tests/nwfilterebiptablestest.c | 21 ------------------ tests/nwfilterxml2firewalltest.c | 3 --- tests/testutils.c | 2 -- tests/vboxsnapshotxmltest.c | 5 ----- tests/virbuftest.c | 23 +++----------------- tests/virfirewalltest.c | 30 -------------------------- tests/virkmodtest.c | 6 +----- tests/virnetdevbandwidthtest.c | 5 ----- tests/virsystemdtest.c | 3 --- tools/virsh-checkpoint.c | 5 ----- tools/virsh-domain-monitor.c | 6 ------ tools/virsh-domain.c | 28 ------------------------ tools/virsh-pool.c | 9 -------- tools/virsh-snapshot.c | 5 ----- tools/virsh-volume.c | 4 ---- tools/vsh.c | 18 ---------------- 28 files changed, 5 insertions(+), 236 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 81006119aa..1fb538b9a8 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30527,8 +30527,6 @@ virDomainMachineNameAppendValid(virBufferPtr buf, bool skip_dot = false; for (; *name; name++) { - if (virBufferError(buf)) - break; if (strlen(virBufferCurrentContent(buf)) >= 64) break; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 94c2e4ef6a..089b28f85b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1592,7 +1592,6 @@ virBufferAsprintf; virBufferCheckErrorInternal; virBufferContentAndReset; virBufferCurrentContent; -virBufferError; virBufferEscape; virBufferEscapeRegex; virBufferEscapeSexpr; diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index d39f1ecb6d..0366deaf8b 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -431,10 +431,6 @@ virNWFilterDetermineMissingVarsRec(virNWFilterDefPtr filter, virBuffer buf = VIR_BUFFER_INITIALIZER; virNWFilterVarAccessPrint(rule->varAccess[j], &buf); - if (virBufferError(&buf)) { - virReportOOMError(); - return -1; - } val = virNWFilterVarValueCreateSimpleCopyValue("1"); if (!val) { diff --git a/src/nwfilter/nwfilter_learnipaddr.c b/src/nwfilter/nwfilter_learnipaddr.c index d7754c0c7a..293007300a 100644 --- a/src/nwfilter/nwfilter_learnipaddr.c +++ b/src/nwfilter/nwfilter_learnipaddr.c @@ -456,11 +456,6 @@ learnIPAddressThread(void *arg) macaddr); } - if (virBufferError(&buf)) { - req->status = ENOMEM; - goto done; - } - filter = virBufferContentAndReset(&buf); if (pcap_compile(handle, &fp, filter, 1, 0) != 0) { diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 7d7262ca39..54c07894c8 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1314,12 +1314,6 @@ get_files(vahControl * ctl) if (vah_add_file(&buf, ctl->newfile, "rwk") != 0) goto cleanup; - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - vah_error(NULL, 0, _("failed to allocate file buffer")); - goto cleanup; - } - rc = 0; ctl->files = virBufferContentAndReset(&buf); @@ -1507,11 +1501,6 @@ main(int argc, char **argv) virBufferAdd(&buf, ctl->files, -1); } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - vah_error(ctl, 1, _("failed to allocate buffer")); - } - included_files = virBufferContentAndReset(&buf); /* (re)create the include file using included_files */ diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index a9d8e6c3d5..80eccaadce 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -446,12 +446,6 @@ virBitmapFormat(virBitmapPtr bitmap) start = prev = cur; } - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); - return NULL; - } - return virBufferContentAndReset(&buf); } diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index e6480ca4ef..b513c59268 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -276,21 +276,6 @@ void virBufferFreeAndReset(virBufferPtr buf) memset(buf, 0, sizeof(*buf)); } -/** - * virBufferError: - * @buf: the buffer - * - * Check to see if the buffer is in an error state due - * to failed memory allocation or usage error - * - * Return positive errno value or -1 on usage error, 0 if normal - */ -int -virBufferError(const virBuffer *buf G_GNUC_UNUSED) -{ - return 0; -} - /** * virBufferCheckErrorInternal: * @buf: the buffer diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index 9adec89f57..c7f0568067 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -43,7 +43,6 @@ struct _virBuffer { const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); -int virBufferError(const virBuffer *buf); int virBufferCheckErrorInternal(const virBuffer *buf) ATTRIBUTE_NONNULL(1); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 223a2a824e..6baa0b251f 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -1389,11 +1389,6 @@ virCommandAddEnvBuffer(virCommandPtr cmd, virBufferPtr buf) return; } - if (virBufferError(buf)) { - cmd->has_error = ENOMEM; - virBufferFreeAndReset(buf); - return; - } if (!virBufferUse(buf)) { cmd->has_error = EINVAL; return; @@ -1525,8 +1520,7 @@ virCommandAddArgBuffer(virCommandPtr cmd, virBufferPtr buf) } /* Arg plus trailing NULL. */ - if (virBufferError(buf) || - VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { + if (VIR_RESIZE_N(cmd->args, cmd->maxargs, cmd->nargs, 1 + 1) < 0) { cmd->has_error = ENOMEM; virBufferFreeAndReset(buf); return; diff --git a/src/util/virlog.c b/src/util/virlog.c index 27843363e7..cf0599c880 100644 --- a/src/util/virlog.c +++ b/src/util/virlog.c @@ -1137,11 +1137,6 @@ virLogGetFilters(void) } virLogUnlock(); - if (virBufferError(&filterbuf)) { - virBufferFreeAndReset(&filterbuf); - return NULL; - } - return virBufferContentAndReset(&filterbuf); } @@ -1185,9 +1180,6 @@ virLogGetOutputs(void) } } - if (virBufferError(&outputbuf)) - goto error; - virLogUnlock(); return virBufferContentAndReset(&outputbuf); diff --git a/tests/cputest.c b/tests/cputest.c index 83b494857f..a277224918 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -268,10 +268,6 @@ cpuTestGuestCPU(const void *arg) virBufferAsprintf(&buf, ",%s", data->modelsName); virBufferAddLit(&buf, "-result"); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - goto cleanup; - } result = virBufferContentAndReset(&buf); if (cpuTestCompareXML(data->arch, cpu, result) < 0) diff --git a/tests/networkxml2firewalltest.c b/tests/networkxml2firewalltest.c index b8e974971a..6822a4f4c2 100644 --- a/tests/networkxml2firewalltest.c +++ b/tests/networkxml2firewalltest.c @@ -76,9 +76,6 @@ static int testCompareXMLToArgvFiles(const char *xml, if (networkAddFirewallRules(def) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = actualargv = virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); virCommandSetDryRun(NULL, NULL, NULL); diff --git a/tests/nwfilterebiptablestest.c b/tests/nwfilterebiptablestest.c index 61b3284397..f7fb03396d 100644 --- a/tests/nwfilterebiptablestest.c +++ b/tests/nwfilterebiptablestest.c @@ -109,9 +109,6 @@ testNWFilterEBIPTablesAllTeardown(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.allTeardown("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -180,9 +177,6 @@ testNWFilterEBIPTablesTearOldRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.tearOldRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -229,9 +223,6 @@ testNWFilterEBIPTablesRemoveBasicRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.removeBasicRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -263,9 +254,6 @@ testNWFilterEBIPTablesTearNewRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.tearNewRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -335,9 +323,6 @@ testNWFilterEBIPTablesApplyBasicRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.applyBasicRules("vnet0", &mac) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -425,9 +410,6 @@ testNWFilterEBIPTablesApplyDHCPOnlyRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.applyDHCPOnlyRules("vnet0", &mac, &val, false) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); @@ -498,9 +480,6 @@ testNWFilterEBIPTablesApplyDropAllRules(const void *opaque G_GNUC_UNUSED) if (ebiptables_driver.applyDropAllRules("vnet0") < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actual = virBufferContentAndReset(&buf); virTestClearCommandPath(actual); diff --git a/tests/nwfilterxml2firewalltest.c b/tests/nwfilterxml2firewalltest.c index bef3790da2..6b17a33953 100644 --- a/tests/nwfilterxml2firewalltest.c +++ b/tests/nwfilterxml2firewalltest.c @@ -394,9 +394,6 @@ static int testCompareXMLToArgvFiles(const char *xml, if (ebiptables_driver.applyNewRules("vnet0", inst.rules, inst.nrules) < 0) goto cleanup; - if (virBufferError(&buf)) - goto cleanup; - actualargv = virBufferContentAndReset(&buf); virTestClearCommandPath(actualargv); virCommandSetDryRun(NULL, NULL, NULL); diff --git a/tests/testutils.c b/tests/testutils.c index a141abc91b..da236c74a1 100644 --- a/tests/testutils.c +++ b/tests/testutils.c @@ -763,8 +763,6 @@ virTestLogContentAndReset(void) { char *ret; - if (virBufferError(&testLog.buf)) - return NULL; ret = virBufferContentAndReset(&testLog.buf); if (!ret) ret = g_strdup(""); diff --git a/tests/vboxsnapshotxmltest.c b/tests/vboxsnapshotxmltest.c index 3d6171e266..38dbba9eff 100644 --- a/tests/vboxsnapshotxmltest.c +++ b/tests/vboxsnapshotxmltest.c @@ -36,11 +36,6 @@ testFilterXML(char *xml) virBufferStrcat(&buf, *xmlLine, "\n", NULL); } - if (virBufferError(&buf)) { - virReportOOMError(); - goto cleanup; - } - ret = virBufferContentAndReset(&buf); cleanup: diff --git a/tests/virbuftest.c b/tests/virbuftest.c index 34aa8b678b..56a6ece8f6 100644 --- a/tests/virbuftest.c +++ b/tests/virbuftest.c @@ -29,15 +29,13 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) ret = -1; } if (virBufferGetIndent(buf) != 3 || - virBufferGetEffectiveIndent(buf) != 3 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) != 3) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } virBufferAdjustIndent(buf, -2); if (virBufferGetIndent(buf) != 1 || - virBufferGetEffectiveIndent(buf) != 1 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) != 1) { VIR_TEST_DEBUG("Wrong indentation"); ret = -1; } @@ -50,17 +48,12 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) virBufferAdjustIndent(buf, 3); virBufferFreeAndReset(buf); if (virBufferGetIndent(buf) != 0 || - virBufferGetEffectiveIndent(buf) != 0 || - virBufferError(buf)) { + virBufferGetEffectiveIndent(buf) != 0) { VIR_TEST_DEBUG("Reset didn't clear indentation"); ret = -1; } virBufferAdjustIndent(buf, 2); virBufferAddLit(buf, "1"); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } if (STRNEQ(virBufferCurrentContent(buf), " 1")) { VIR_TEST_DEBUG("Wrong content"); ret = -1; @@ -87,11 +80,6 @@ static int testBufAutoIndent(const void *data G_GNUC_UNUSED) virBufferEscapeShell(buf, " 11"); virBufferAddChar(buf, '\n'); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } - result = virBufferContentAndReset(buf); if (!result || STRNEQ(result, expected)) { virTestDifference(stderr, expected, result); @@ -125,11 +113,6 @@ static int testBufTrim(const void *data G_GNUC_UNUSED) virBufferTrim(buf, "b,,", 1); virBufferTrim(buf, ",", -1); - if (virBufferError(buf)) { - VIR_TEST_DEBUG("Buffer had error"); - return -1; - } - result = virBufferContentAndReset(buf); if (!result || STRNEQ(result, expected)) { virTestDifference(stderr, expected, result); diff --git a/tests/virfirewalltest.c b/tests/virfirewalltest.c index a5323a4256..c4827918c3 100644 --- a/tests/virfirewalltest.c +++ b/tests/virfirewalltest.c @@ -234,9 +234,6 @@ testFirewallSingleGroup(const void *opaque) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -300,9 +297,6 @@ testFirewallRemoveRule(const void *opaque) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -373,9 +367,6 @@ testFirewallManyGroups(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -469,9 +460,6 @@ testFirewallIgnoreFailGroup(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -543,9 +531,6 @@ testFirewallIgnoreFailRule(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -611,9 +596,6 @@ testFirewallNoRollback(const void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -698,9 +680,6 @@ testFirewallSingleRollback(const void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -788,9 +767,6 @@ testFirewallManyRollback(const void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -908,9 +884,6 @@ testFirewallChainedRollback(const void *opaque G_GNUC_UNUSED) goto cleanup; } - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (STRNEQ_NULLABLE(expected, actual)) { @@ -1085,9 +1058,6 @@ testFirewallQuery(const void *opaque G_GNUC_UNUSED) if (virFirewallApply(fw) < 0) goto cleanup; - if (virBufferError(&cmdbuf)) - goto cleanup; - actual = virBufferCurrentContent(&cmdbuf); if (expectedLineError) { diff --git a/tests/virkmodtest.c b/tests/virkmodtest.c index 853f4ea14e..e013f8f3b6 100644 --- a/tests/virkmodtest.c +++ b/tests/virkmodtest.c @@ -69,11 +69,7 @@ checkOutput(virBufferPtr buf, const char *exp_cmd) char *actual_cmd = NULL; if (!(actual_cmd = virBufferContentAndReset(buf))) { - int err = virBufferError(buf); - if (err) - fprintf(stderr, "buffer's in error state: %d", err); - else - fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); + fprintf(stderr, "cannot compare buffer to exp: %s", exp_cmd); goto cleanup; } diff --git a/tests/virnetdevbandwidthtest.c b/tests/virnetdevbandwidthtest.c index 59647173c3..8039fedbc4 100644 --- a/tests/virnetdevbandwidthtest.c +++ b/tests/virnetdevbandwidthtest.c @@ -84,11 +84,6 @@ testVirNetDevBandwidthSet(const void *data) goto cleanup; if (!(actual_cmd = virBufferContentAndReset(&buf))) { - int err = virBufferError(&buf); - if (err) { - fprintf(stderr, "buffer's in error state: %d", err); - goto cleanup; - } /* This is interesting, no command has been executed. * Maybe that's expected, actually. */ } diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 1a78f006cc..b85259f61f 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -570,9 +570,6 @@ testActivation(bool useNames) setenv("LISTEN_FDS", nfdstr, 1); setenv("LISTEN_PID", pidstr, 1); - if (virBufferError(&names)) - goto cleanup; - if (useNames) setenv("LISTEN_FDNAMES", virBufferCurrentContent(&names), 1); else diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c index 7fd3914ef2..f9749b5f6d 100644 --- a/tools/virsh-checkpoint.c +++ b/tools/virsh-checkpoint.c @@ -267,11 +267,6 @@ cmdCheckpointCreateAs(vshControl *ctl, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domaincheckpoint>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - goto cleanup; - } - buffer = virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index bfff08b0f6..d3beda5670 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -2410,12 +2410,6 @@ cmdDomIfAddr(vshControl *ctl, const vshCmd *cmd) type, iface->addrs[j].addr, iface->addrs[j].prefix); - if (virBufferError(&buf)) { - virBufferFreeAndReset(&buf); - virReportOOMError(); - goto cleanup; - } - ip_addr_str = virBufferContentAndReset(&buf); if (!ip_addr_str) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2f3ac2d430..ae7777df09 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -754,11 +754,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</disk>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } - xml = virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { @@ -1072,11 +1067,6 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</interface>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } - xml = virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { @@ -8396,10 +8386,6 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect new description/title")); - goto cleanup; - } desc = virBufferContentAndReset(&buf); if (edit || desc) { @@ -9517,10 +9503,6 @@ cmdQemuMonitorCommand(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect command")); - return false; - } monitor_cmd = virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "hmp")) @@ -9818,10 +9800,6 @@ cmdQemuAgentCommand(vshControl *ctl, const vshCmd *cmd) virBufferTrim(&buf, " ", -1); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to collect command")); - goto cleanup; - } guest_agent_cmd = virBufferContentAndReset(&buf); judge = vshCommandOptInt(ctl, cmd, "timeout", &timeout); @@ -11551,12 +11529,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd) params = true; } - /* Ensure we can print our URI */ - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to create display URI")); - goto cleanup; - } - /* Print out our full URI */ VIR_FREE(output); output = virBufferContentAndReset(&buf); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index bd876aefda..2b315caaa7 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -416,11 +416,6 @@ virshBuildPoolXML(vshControl *ctl, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</pool>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } - *xml = virBufferContentAndReset(&buf); *retname = name; return true; @@ -1480,10 +1475,6 @@ cmdPoolDiscoverSourcesAs(vshControl * ctl, const vshCmd * cmd G_GNUC_UNUSED) } virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</source>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - return false; - } srcSpec = virBufferContentAndReset(&buf); } diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 751186ebf8..a42397b42e 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -445,11 +445,6 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domainsnapshot>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Out of memory")); - goto cleanup; - } - buffer = virBufferContentAndReset(&buf); if (vshCommandOptBool(cmd, "print-xml")) { diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index d09d4435ad..3637e7f603 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -341,10 +341,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</volume>\n"); - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - goto cleanup; - } xml = virBufferContentAndReset(&buf); if (printXML) { diff --git a/tools/vsh.c b/tools/vsh.c index 58ee94b52f..5bab5b5c83 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -2269,9 +2269,6 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format, virBufferTrim(&buf, "\n", -1); virBufferAddChar(&buf, '\n'); - if (virBufferError(&buf)) - goto error; - str = virBufferContentAndReset(&buf); len = strlen(str); @@ -2532,9 +2529,6 @@ vshTreePrintInternal(vshControl *ctl, int ret = -1; const char *dev = (lookup)(devid, false, opaque); - if (virBufferError(indent)) - goto cleanup; - /* Print this device, with indent if not at root */ vshPrint(ctl, "%s%s%s\n", virBufferCurrentContent(indent), root ? "" : "+- ", dev); @@ -2543,8 +2537,6 @@ vshTreePrintInternal(vshControl *ctl, if (!root) { virBufferAddChar(indent, devid == lastdev ? ' ' : '|'); virBufferAddChar(indent, ' '); - if (virBufferError(indent)) - goto cleanup; } /* Determine the index of the last child device */ @@ -2561,8 +2553,6 @@ vshTreePrintInternal(vshControl *ctl, /* Finally print all children */ virBufferAddLit(indent, " "); - if (virBufferError(indent)) - goto cleanup; for (i = 0; i < num_devices; i++) { const char *parent = (lookup)(i, true, opaque); @@ -3318,10 +3308,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) if (xml) { virBufferEscapeString(&xmlbuf, "%s", arg); - if (virBufferError(&xmlbuf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } str = virBufferContentAndReset(&xmlbuf); } else { str = g_strdup(arg); @@ -3335,10 +3321,6 @@ cmdEcho(vshControl *ctl, const vshCmd *cmd) VIR_FREE(str); } - if (virBufferError(&buf)) { - vshError(ctl, "%s", _("Failed to allocate XML buffer")); - return false; - } arg = virBufferContentAndReset(&buf); if (arg) { if (err) -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:35PM +0200, Peter Krempa wrote:
The function now never returned an error so we can drop it fully.
now does not return an error
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 2 -- src/libvirt_private.syms | 1 - src/nwfilter/nwfilter_gentech_driver.c | 4 ---- src/nwfilter/nwfilter_learnipaddr.c | 5 ----- src/security/virt-aa-helper.c | 11 ---------- src/util/virbitmap.c | 6 ------ src/util/virbuffer.c | 15 ------------- src/util/virbuffer.h | 1 - src/util/vircommand.c | 8 +------ src/util/virlog.c | 8 ------- tests/cputest.c | 4 ---- tests/networkxml2firewalltest.c | 3 --- tests/nwfilterebiptablestest.c | 21 ------------------ tests/nwfilterxml2firewalltest.c | 3 --- tests/testutils.c | 2 -- tests/vboxsnapshotxmltest.c | 5 ----- tests/virbuftest.c | 23 +++----------------- tests/virfirewalltest.c | 30 -------------------------- tests/virkmodtest.c | 6 +----- tests/virnetdevbandwidthtest.c | 5 ----- tests/virsystemdtest.c | 3 --- tools/virsh-checkpoint.c | 5 ----- tools/virsh-domain-monitor.c | 6 ------ tools/virsh-domain.c | 28 ------------------------ tools/virsh-pool.c | 9 -------- tools/virsh-snapshot.c | 5 ----- tools/virsh-volume.c | 4 ---- tools/vsh.c | 18 ---------------- 28 files changed, 5 insertions(+), 236 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The function now never returned an error so we can drop it fully. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/bhyve/bhyve_command.c | 3 - src/bhyve/bhyve_driver.c | 5 - src/conf/capabilities.c | 16 --- src/conf/checkpoint_conf.c | 3 - src/conf/cpu_conf.c | 7 -- src/conf/domain_addr.c | 2 - src/conf/domain_capabilities.c | 1 - src/conf/domain_conf.c | 38 ------- src/conf/interface_conf.c | 3 - src/conf/network_conf.c | 3 - src/conf/node_device_conf.c | 3 - src/conf/nwfilter_conf.c | 9 -- src/conf/secret_conf.c | 3 - src/conf/snapshot_conf.c | 3 - src/conf/storage_conf.c | 12 -- src/conf/virnetworkobj.c | 3 - src/conf/virnetworkportdef.c | 3 - src/conf/virnwfilterbindingdef.c | 3 - src/conf/virnwfilterbindingobj.c | 3 - src/conf/virsavecookie.c | 3 - src/cpu/cpu_map.c | 2 - src/cpu/cpu_x86.c | 10 -- src/esx/esx_driver.c | 12 -- src/esx/esx_util.c | 6 - src/esx/esx_vi.c | 15 --- src/esx/esx_vi_methods.c | 3 - src/hyperv/hyperv_driver.c | 3 - src/hyperv/hyperv_wmi.c | 10 -- src/libvirt_private.syms | 1 - src/libxl/libxl_conf.c | 5 - src/libxl/libxl_driver.c | 2 - src/libxl/libxl_migration.c | 3 - src/libxl/xen_common.c | 13 --- src/libxl/xen_xl.c | 9 -- src/libxl/xen_xm.c | 3 - src/locking/lock_driver_sanlock.c | 3 - src/lxc/lxc_container.c | 3 - src/lxc/lxc_controller.c | 3 - src/lxc/lxc_driver.c | 2 - src/lxc/lxc_fuse.c | 4 - src/network/bridge_driver.c | 6 - src/node_device/node_device_udev.c | 3 - src/nwfilter/nwfilter_ebiptables_driver.c | 8 -- src/nwfilter/nwfilter_gentech_driver.c | 2 - src/phyp/phyp_driver.c | 4 - src/qemu/qemu_capabilities.c | 3 +- src/qemu/qemu_command.c | 130 ---------------------- src/qemu/qemu_domain.c | 4 - src/qemu/qemu_driver.c | 2 - src/qemu/qemu_migration_cookie.c | 3 - src/qemu/qemu_monitor_json.c | 3 - src/rpc/virnetlibsshsession.c | 6 - src/rpc/virnetsocket.c | 8 -- src/rpc/virnetsshsession.c | 6 - src/storage/storage_backend_rbd.c | 6 - src/storage/storage_util.c | 13 --- src/util/virbitmap.c | 1 - src/util/virbuffer.c | 14 --- src/util/virbuffer.h | 13 --- src/util/vircommand.c | 3 - src/util/virconf.c | 6 - src/util/virdnsmasq.c | 6 - src/util/virfilecache.c | 3 - src/util/virnetdevopenvswitch.c | 3 - src/util/virpidfile.c | 7 -- src/util/virqemu.c | 3 - src/util/virresctrl.c | 4 +- src/util/virstoragefile.c | 3 - src/util/virstring.c | 5 - src/util/virsysinfo.c | 3 - src/util/virsystemd.c | 6 - src/util/viruri.c | 3 - src/util/virxml.c | 5 - src/vmx/vmx.c | 3 - src/vz/vz_driver.c | 5 - tests/qemublocktest.c | 6 - tests/qemumonitorjsontest.c | 6 - tests/qemumonitortestutils.c | 2 - tests/vircgrouptest.c | 2 - tools/virsh-domain.c | 2 - tools/vsh.c | 3 - 81 files changed, 3 insertions(+), 559 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 8ea76cee2e..48336ffa1b 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -227,9 +227,6 @@ bhyveBuildAHCIControllerArgStr(const virDomainDef *def, virBufferFreeAndReset(&device); } - if (virBufferCheckError(&buf) < 0) - goto error; - virCommandAddArg(cmd, "-s"); virCommandAddArgFormat(cmd, "%d:0,ahci%s", controller->info.addr.pci.slot, diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index e3d984f69a..7da48a08d5 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -258,8 +258,6 @@ bhyveConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, privconn->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -752,9 +750,6 @@ bhyveConnectDomainXMLToNative(virConnectPtr conn, virBufferAdd(&buf, virCommandToString(cmd, false), -1); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - ret = virBufferContentAndReset(&buf); cleanup: diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 697d464fe9..953464b09d 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -734,10 +734,6 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps, if (virBufferCurrentContent(&buf) && !virBufferCurrentContent(&buf)[0]) virBufferAsprintf(&buf, "%s", _("any configuration")); - if (virBufferCheckError(&buf) < 0) { - virBufferFreeAndReset(&buf); - goto error; - } virReportError(VIR_ERR_INVALID_ARG, _("could not find capabilities for %s"), @@ -930,9 +926,6 @@ virCapabilitiesFormatResctrlMonitor(virBufferPtr buf, monitor->features[i]); } - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - virBufferAddBuffer(buf, &childrenBuf); virBufferAddLit(buf, "</monitor>\n"); @@ -1014,9 +1007,6 @@ virCapabilitiesFormatCaches(virBufferPtr buf, controls->max_allocation); } - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -1068,9 +1058,6 @@ virCapabilitiesFormatMemoryBandwidth(virBufferPtr buf, control->granularity, control->min, control->max_allocation); - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, ">\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -1367,9 +1354,6 @@ virCapabilitiesFormatXML(virCapsPtr caps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</capabilities>\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); error: diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 4fa743e0b0..3b7d848079 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -499,9 +499,6 @@ virDomainCheckpointDefFormatInternal(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</domaincheckpoint>\n"); - if (virBufferCheckError(buf) < 0) - goto error; - return 0; error: diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 1d9feb2f0a..2b644638a7 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -668,9 +668,6 @@ virCPUDefFormat(virCPUDefPtr def, if (virCPUDefFormatBufFull(&buf, def, numa) < 0) goto cleanup; - if (virBufferCheckError(&buf) < 0) - goto cleanup; - return virBufferContentAndReset(&buf); cleanup: @@ -731,10 +728,6 @@ virCPUDefFormatBufFull(virBufferPtr buf, if (virDomainNumaDefCPUFormatXML(&childrenBuf, numa) < 0) goto cleanup; - if (virBufferCheckError(&attributeBuf) < 0 || - virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - /* Put it all together */ if (virBufferUse(&attributeBuf) || virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "<cpu"); diff --git a/src/conf/domain_addr.c b/src/conf/domain_addr.c index dd8e04576a..9b588226e3 100644 --- a/src/conf/domain_addr.c +++ b/src/conf/domain_addr.c @@ -1985,8 +1985,6 @@ virDomainUSBAddressPortFormat(unsigned int *port) { virBuffer buf = VIR_BUFFER_INITIALIZER; virDomainUSBAddressPortFormatBuf(&buf, port); - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c index 3c4c7fd6d1..09bf047647 100644 --- a/src/conf/domain_capabilities.c +++ b/src/conf/domain_capabilities.c @@ -654,7 +654,6 @@ virDomainCapsFormat(virDomainCapsPtr const caps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domainCapabilities>\n"); - virBufferCheckError(&buf); return virBufferContentAndReset(&buf); } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1fb538b9a8..778858fe3e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -24854,9 +24854,6 @@ virDomainFSDefFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; - if (virBufferUse(&driverBuf)) { virBufferAddLit(buf, "<driver"); virBufferAddBuffer(buf, &driverBuf); @@ -25297,9 +25294,6 @@ virDomainVirtioNetGuestOptsFormat(char **outstr, } virBufferTrim(&buf, " ", -1); - if (virBufferCheckError(&buf) < 0) - return -1; - *outstr = virBufferContentAndReset(&buf); return 0; } @@ -25340,9 +25334,6 @@ virDomainVirtioNetHostOptsFormat(char **outstr, } virBufferTrim(&buf, " ", -1); - if (virBufferCheckError(&buf) < 0) - return -1; - *outstr = virBufferContentAndReset(&buf); return 0; } @@ -25380,9 +25371,6 @@ virDomainVirtioNetDriverFormat(char **outstr, virDomainVirtioOptionsFormat(&buf, def->virtio); - if (virBufferCheckError(&buf) < 0) - return -1; - *outstr = virBufferContentAndReset(&buf); return 0; } @@ -26083,9 +26071,6 @@ virDomainSmartcardDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) goto cleanup; - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - virBufferAsprintf(buf, "<smartcard mode='%s'", mode); if (def->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH && virDomainChrAttrsDefFormat(buf, def->data.passthru, false) < 0) { @@ -26196,9 +26181,6 @@ virDomainSoundDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) goto cleanup; - if (virBufferCheckError(&childBuf) < 0) - goto cleanup; - virBufferAsprintf(buf, "<sound model='%s'", model); if (virBufferUse(&childBuf)) { virBufferAddLit(buf, ">\n"); @@ -26584,8 +26566,6 @@ virDomainVideoDefFormat(virBufferPtr buf, virBufferAddLit(buf, "<video>\n"); virBufferAdjustIndent(buf, 2); virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - if (virBufferCheckError(&driverBuf) < 0) - goto cleanup; if (virBufferUse(&driverBuf) || (def->driver && def->driver->vgaconf) || def->backend != VIR_DOMAIN_VIDEO_BACKEND_TYPE_DEFAULT) { virBufferAddLit(buf, "<driver"); @@ -27663,9 +27643,6 @@ virDomainCachetuneDefFormat(virBufferPtr buf, goto cleanup; } - if (virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - if (!virBufferUse(&childrenBuf)) { ret = 0; goto cleanup; @@ -27724,9 +27701,6 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, &childrenBuf) < 0) goto cleanup; - if (virBufferCheckError(&childrenBuf) < 0) - goto cleanup; - if (!virBufferUse(&childrenBuf)) { ret = 0; goto cleanup; @@ -27869,9 +27843,6 @@ virDomainCputuneDefFormat(virBufferPtr buf, for (i = 0; i < def->nresctrls; i++) virDomainMemorytuneDefFormat(&childrenBuf, def->resctrls[i], flags); - if (virBufferCheckError(&childrenBuf) < 0) - return -1; - if (virBufferUse(&childrenBuf)) { virBufferAddLit(buf, "<cputune>\n"); virBufferAddBuffer(buf, &childrenBuf); @@ -28938,9 +28909,6 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def, virBufferAdjustIndent(buf, -2); virBufferAsprintf(buf, "</%s>\n", rootname); - if (virBufferCheckError(buf) < 0) - goto error; - return 0; error: @@ -29015,9 +28983,6 @@ virDomainObjFormat(virDomainXMLOptionPtr xmlopt, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</domstatus>\n"); - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: @@ -30452,8 +30417,6 @@ virDomainGetBlkioParametersAssignFromDef(virDomainDefPtr def, def->blkio.devices[i].param); \ } \ virBufferTrim(&buf, ",", -1); \ - if (virBufferCheckError(&buf) < 0) \ - goto error; \ data = virBufferContentAndReset(&buf); \ if (virTypedParameterAssign(&(params[(*nparams)++]), name, \ VIR_TYPED_PARAM_STRING, data) < 0) \ @@ -30571,7 +30534,6 @@ virDomainGenerateMachineName(const char *drivername, virBufferAsprintf(&buf, "%d-", id); virDomainMachineNameAppendValid(&buf, name); - virBufferCheckError(&buf); return virBufferContentAndReset(&buf); } diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c index 69ac049eaa..fbfd855395 100644 --- a/src/conf/interface_conf.c +++ b/src/conf/interface_conf.c @@ -1124,9 +1124,6 @@ virInterfaceDefDevFormat(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</interface>\n"); - if (virBufferCheckError(buf) < 0) - goto cleanup; - return 0; cleanup: diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 1d20d28f46..17cb73a899 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2660,9 +2660,6 @@ virNetworkDefFormat(const virNetworkDef *def, if (virNetworkDefFormatBuf(&buf, def, xmlopt, flags) < 0) goto error; - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 7eb52dbf85..767524841f 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -610,9 +610,6 @@ virNodeDeviceDefFormat(const virNodeDeviceDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</device>\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/conf/nwfilter_conf.c b/src/conf/nwfilter_conf.c index cd97eb87ac..48f5720d85 100644 --- a/src/conf/nwfilter_conf.c +++ b/src/conf/nwfilter_conf.c @@ -951,8 +951,6 @@ virNWFilterPrintTCPFlags(uint8_t flags) { virBuffer buf = VIR_BUFFER_INITIALIZER; printTCPFlags(&buf, flags); - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -2600,15 +2598,11 @@ virNWFilterIsAllowedChain(const char *chainname) printed = true; } - if (virBufferCheckError(&buf) < 0) - goto err_exit; - msg = virBufferContentAndReset(&buf); virReportError(VIR_ERR_INVALID_ARG, "%s", msg); VIR_FREE(msg); - err_exit: return NULL; } @@ -3078,9 +3072,6 @@ virNWFilterDefFormat(const virNWFilterDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</filter>\n"); - if (virBufferCheckError(&buf) < 0) - goto err_exit; - return virBufferContentAndReset(&buf); err_exit: diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c index 3716d5731f..0ec9bce987 100644 --- a/src/conf/secret_conf.c +++ b/src/conf/secret_conf.c @@ -298,9 +298,6 @@ virSecretDefFormat(const virSecretDef *def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</secret>\n"); - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index f9fbca3c07..14e0d37063 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -926,9 +926,6 @@ virDomainSnapshotDefFormatInternal(virBufferPtr buf, virBufferAdjustIndent(buf, -2); virBufferAddLit(buf, "</domainsnapshot>\n"); - if (virBufferCheckError(buf) < 0) - goto error; - return 0; error: diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index f212eefe25..9c85721a23 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -1235,9 +1235,6 @@ virStoragePoolDefFormat(virStoragePoolDefPtr def) if (virStoragePoolDefFormatBuf(&buf, def) < 0) goto error; - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: @@ -1672,9 +1669,6 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</volume>\n"); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - return virBufferContentAndReset(&buf); cleanup: @@ -1716,9 +1710,6 @@ virStoragePoolSaveState(const char *stateFile, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</poolstate>\n"); - if (virBufferCheckError(&buf) < 0) - return -1; - if (!(xml = virBufferContentAndReset(&buf))) return -1; @@ -1788,9 +1779,6 @@ virStoragePoolSourceListFormat(virStoragePoolSourceListPtr def) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</sources>\n"); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - return virBufferContentAndReset(&buf); cleanup: diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index e7017bffa9..b9db7cb876 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -843,9 +843,6 @@ virNetworkObjFormat(virNetworkObjPtr obj, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</networkstatus>"); - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 459384611c..53c2a52e70 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -323,9 +323,6 @@ virNetworkPortDefFormat(const virNetworkPortDef *def) return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/conf/virnwfilterbindingdef.c b/src/conf/virnwfilterbindingdef.c index dbd0a9a04f..7d813353ef 100644 --- a/src/conf/virnwfilterbindingdef.c +++ b/src/conf/virnwfilterbindingdef.c @@ -230,9 +230,6 @@ virNWFilterBindingDefFormat(const virNWFilterBindingDef *def) return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/conf/virnwfilterbindingobj.c b/src/conf/virnwfilterbindingobj.c index 48d53fafb1..f0bd67e9bd 100644 --- a/src/conf/virnwfilterbindingobj.c +++ b/src/conf/virnwfilterbindingobj.c @@ -300,8 +300,5 @@ virNWFilterBindingObjFormat(const virNWFilterBindingObj *obj) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</filterbindingstatus>\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/conf/virsavecookie.c b/src/conf/virsavecookie.c index 37a3808481..bdc22bb324 100644 --- a/src/conf/virsavecookie.c +++ b/src/conf/virsavecookie.c @@ -133,9 +133,6 @@ virSaveCookieFormat(virObjectPtr obj, if (virSaveCookieFormatBuf(&buf, obj, saveCookie) < 0) goto error; - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: diff --git a/src/cpu/cpu_map.c b/src/cpu/cpu_map.c index cb9f7c243f..dffb6ea7e8 100644 --- a/src/cpu/cpu_map.c +++ b/src/cpu/cpu_map.c @@ -201,8 +201,6 @@ int cpuMapLoad(const char *arch, goto cleanup; virBufferAsprintf(&buf, "./arch[@name='%s']", arch); - if (virBufferCheckError(&buf) < 0) - goto cleanup; xpath = virBufferContentAndReset(&buf); diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index d7fcb3b147..abe4865ec2 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1652,9 +1652,6 @@ virCPUx86DataFormat(const virCPUData *data) } virBufferAddLit(&buf, "</cpudata>\n"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -1992,9 +1989,6 @@ x86FormatSignatures(virCPUx86ModelPtr model) virBufferTrim(&buf, ",", -1); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -3075,10 +3069,6 @@ virCPUx86UpdateLive(virCPUDefPtr cpu, virBufferTrim(&bufAdded, ",", -1); virBufferTrim(&bufRemoved, ",", -1); - if (virBufferCheckError(&bufAdded) < 0 || - virBufferCheckError(&bufRemoved) < 0) - goto cleanup; - added = virBufferContentAndReset(&bufAdded); removed = virBufferContentAndReset(&bufRemoved); diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 8e39075701..130f349133 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -325,9 +325,6 @@ esxFormatVMXFileName(const char *fileName, void *opaque) virBufferAddChar(&buffer, separator); virBufferAdd(&buffer, directoryAndFileName, -1); - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - result = virBufferContentAndReset(&buffer); } else if (*fileName == '/') { /* FIXME: need to deal with Windows paths here too */ @@ -2413,9 +2410,6 @@ esxDomainScreenshot(virDomainPtr domain, virStreamPtr stream, domain->conn->uri->server, domain->conn->uri->port); virBufferURIEncodeString(&buffer, virtualMachine->obj->value); - if (virBufferCheckError(&buffer)) - goto cleanup; - url = virBufferContentAndReset(&buffer); mimeType = g_strdup("image/png"); @@ -2634,9 +2628,6 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) virBufferAddLit(&buffer, "&dsName="); virBufferURIEncodeString(&buffer, datastoreName); - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - url = virBufferContentAndReset(&buffer); if (esxVI_CURL_Download(priv->primary->curl, url, &vmx, 0, NULL) < 0) @@ -3100,9 +3091,6 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags) virBufferAddLit(&buffer, "&dsName="); virBufferURIEncodeString(&buffer, datastoreName); - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - url = virBufferContentAndReset(&buffer); /* Check, if VMX file already exists */ diff --git a/src/esx/esx_util.c b/src/esx/esx_util.c index 6f4ee3444f..c265528056 100644 --- a/src/esx/esx_util.c +++ b/src/esx/esx_util.c @@ -398,9 +398,6 @@ esxUtil_EscapeBase64(const char *string) } } - if (virBufferCheckError(&buffer) < 0) - return NULL; - return virBufferContentAndReset(&buffer); } @@ -464,8 +461,5 @@ esxUtil_EscapeForXml(const char *string) virBufferEscapeString(&buffer, "%s", string); - if (virBufferCheckError(&buffer) < 0) - return NULL; - return virBufferContentAndReset(&buffer); } diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 78e61ecd24..3823ea0f07 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -415,9 +415,6 @@ esxVI_CURL_Download(esxVI_CURL *curl, const char *url, char **content, goto cleanup; } - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - if (length) *length = virBufferUse(&buffer); @@ -1237,9 +1234,6 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - ctx->datacenterPath = virBufferContentAndReset(&buffer); /* Lookup (Cluster)ComputeResource */ @@ -1302,9 +1296,6 @@ esxVI_Context_LookupManagedObjectsByPath(esxVI_Context *ctx, const char *path) goto cleanup; } - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - ctx->computeResourcePath = virBufferContentAndReset(&buffer); /* Lookup HostSystem */ @@ -1439,9 +1430,6 @@ esxVI_Context_Execute(esxVI_Context *ctx, const char *methodName, if ((*response)->responseCode < 0) goto cleanup; - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - (*response)->content = virBufferContentAndReset(&buffer); if ((*response)->responseCode == 500 || (*response)->responseCode == 200) { @@ -4330,9 +4318,6 @@ esxVI_HandleVirtualMachineQuestion ++answerIndex; } - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - possibleAnswers = virBufferContentAndReset(&buffer); } diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index 3156a132d8..616b202d09 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -122,9 +122,6 @@ \ virBufferAddLit(&buffer, "</"#_name">"); \ virBufferAddLit(&buffer, ESX_VI__SOAP__REQUEST_FOOTER); \ - \ - if (virBufferCheckError(&buffer) < 0) \ - goto cleanup; \ \ request = virBufferContentAndReset(&buffer); \ \ diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index 542253b8b8..0378478fc7 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -865,9 +865,6 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) notes++; } - if (virBufferCheckError(&buf)) - goto cleanup; - def->description = virBufferContentAndReset(&buf); } diff --git a/src/hyperv/hyperv_wmi.c b/src/hyperv/hyperv_wmi.c index 04f82389c1..a70093700a 100644 --- a/src/hyperv/hyperv_wmi.c +++ b/src/hyperv/hyperv_wmi.c @@ -511,11 +511,6 @@ hypervSerializeEprParam(hypervParamPtr p, hypervPrivate *priv, } wsmc_set_action_option(options, FLAG_ENUMERATION_ENUM_EPR); - /* Get query and create filter based on it */ - if (virBufferCheckError(p->epr.query) < 0) { - virBufferFreeAndReset(p->epr.query); - goto cleanup; - } query_string = virBufferContentAndReset(p->epr.query); filter = filter_create_simple(WSM_WQL_FILTER_DIALECT, query_string); @@ -983,11 +978,6 @@ hypervEnumAndPull(hypervPrivate *priv, hypervWqlQueryPtr wqlQuery, XML_TYPE_PTR data = NULL; hypervObject *object; - if (virBufferCheckError(wqlQuery->query) < 0) { - virBufferFreeAndReset(wqlQuery->query); - return -1; - } - query_string = virBufferContentAndReset(wqlQuery->query); if (list == NULL || *list != NULL) { diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 089b28f85b..94509d6f43 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1589,7 +1589,6 @@ virBufferAddChar; virBufferAddStr; virBufferAdjustIndent; virBufferAsprintf; -virBufferCheckErrorInternal; virBufferContentAndReset; virBufferCurrentContent; virBufferEscape; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 3f08f0f710..2583023cd5 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -948,9 +948,6 @@ libxlMakeNetworkDiskSrcStr(virStorageSourcePtr src, if (src->configFile) virBufferEscape(&buf, '\\', ":", ":conf=%s", src->configFile); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - ret = virBufferContentAndReset(&buf); break; } @@ -1314,8 +1311,6 @@ libxlMakeNic(virDomainDefPtr def, } } } - if (virBufferCheckError(&buf) < 0) - goto cleanup; x_nic->bridge = g_strdup(virBufferCurrentContent(&buf)); G_GNUC_FALLTHROUGH; case VIR_DOMAIN_NET_TYPE_ETHERNET: diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5cc6b87b8c..7104356abe 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -951,8 +951,6 @@ libxlConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } diff --git a/src/libxl/libxl_migration.c b/src/libxl/libxl_migration.c index 0a57b6fcb0..459880512f 100644 --- a/src/libxl/libxl_migration.c +++ b/src/libxl/libxl_migration.c @@ -134,9 +134,6 @@ libxlMigrationBakeCookie(libxlMigrationCookiePtr mig, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</libxl-migration>\n"); - if (virBufferCheckError(&buf) < 0) - return -1; - *cookieout = virBufferContentAndReset(&buf); *cookieoutlen = strlen(*cookieout) + 1; diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index cc9039a0cf..28b1bcf7c7 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -1598,9 +1598,6 @@ xenFormatSxprChr(virDomainChrDefPtr def, return -1; } - if (virBufferCheckError(buf) < 0) - return -1; - return 0; } @@ -1619,8 +1616,6 @@ xenFormatSerial(virConfValuePtr list, virDomainChrDefPtr serial) } else { virBufferAddLit(&buf, "none"); } - if (virBufferCheckError(&buf) < 0) - goto cleanup; if (VIR_ALLOC(val) < 0) goto cleanup; @@ -1787,9 +1782,6 @@ xenFormatNet(virConnectPtr conn, if (net->bandwidth && net->bandwidth->out && net->bandwidth->out->average) virBufferAsprintf(&buf, ",rate=%lluKB/s", net->bandwidth->out->average); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - if (VIR_ALLOC(val) < 0) goto cleanup; @@ -2318,8 +2310,6 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def) virBufferAsprintf(&buf, ",keymap=%s", def->graphics[0]->data.vnc.keymap); } - if (virBufferCheckError(&buf) < 0) - return -1; vfbstr = virBufferContentAndReset(&buf); @@ -2372,9 +2362,6 @@ xenFormatSound(virConfPtr conf, virDomainDefPtr def) virBufferEscapeSexpr(&buf, "%s", model); } - if (virBufferCheckError(&buf) < 0) - return -1; - str = virBufferContentAndReset(&buf); return xenConfigSetString(conf, "soundhw", str); diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 6bdad2a59d..4afa520465 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1428,9 +1428,6 @@ xenFormatXLVnode(virConfValuePtr list, int ret = -1; virConfValuePtr numaPnode, tmp; - if (virBufferCheckError(buf) < 0) - goto cleanup; - if (VIR_ALLOC(numaPnode) < 0) goto cleanup; @@ -1623,9 +1620,6 @@ xenFormatXLDiskSrcNet(virStorageSourcePtr src) } } - if (virBufferCheckError(&buf) < 0) - goto cleanup; - ret = virBufferContentAndReset(&buf); break; } @@ -1748,9 +1742,6 @@ xenFormatXLDisk(virConfValuePtr list, virDomainDiskDefPtr disk) if (target) virBufferAsprintf(&buf, ",target=%s", target); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - if (VIR_ALLOC(val) < 0) goto cleanup; diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index fdf4e1cd29..c039614079 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -351,9 +351,6 @@ xenFormatXMDisk(virConfValuePtr list, return -1; } - if (virBufferCheckError(&buf) < 0) - goto cleanup; - if (VIR_ALLOC(val) < 0) goto cleanup; diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index beeeb6066b..018f07aba7 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -862,9 +862,6 @@ virLockManagerSanlockRegisterKillscript(int sock, virBufferEscape(&buf, '\\', "\\ ", "%s", virDomainLockFailureTypeToString(action)); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - /* Unfortunately, sanlock_killpath() does not use const for either * path or args even though it will just copy them into its own * buffers. diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 88dc2e2bdf..a18b214a25 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -217,9 +217,6 @@ static virCommandPtr lxcContainerBuildInitCmd(virDomainDefPtr vmDef, } virBufferTrim(&buf, NULL, 1); - if (virBufferCheckError(&buf) < 0) - return NULL; - virUUIDFormat(vmDef->uuid, uuidstr); cmd = virCommandNew(vmDef->os.init); diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 0c5b9e713d..5ae7608246 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -1399,9 +1399,6 @@ virLXCControllerSetupUsernsMap(virDomainIdMapEntryPtr map, virBufferAsprintf(&map_value, "%u %u %u\n", map[i].start, map[i].target, map[i].count); - if (virBufferCheckError(&map_value) < 0) - goto cleanup; - VIR_DEBUG("Set '%s' to '%s'", path, virBufferCurrentContent(&map_value)); if (virFileWriteStr(path, virBufferCurrentContent(&map_value), 0) < 0) { diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 41a6a446bd..e462ecf263 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -5045,8 +5045,6 @@ lxcConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } diff --git a/src/lxc/lxc_fuse.c b/src/lxc/lxc_fuse.c index b64b275a87..07cc620fab 100644 --- a/src/lxc/lxc_fuse.c +++ b/src/lxc/lxc_fuse.c @@ -223,10 +223,6 @@ static int lxcProcReadMeminfo(char *hostpath, virDomainDefPtr def, virBufferAdd(new_meminfo, line, -1); } - if (virBufferCheckError(new_meminfo) < 0) { - res = -errno; - goto cleanup; - } } res = strlen(virBufferCurrentContent(new_meminfo)); if (res > size) diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c index fcaa6a48ae..ea9b22873e 100644 --- a/src/network/bridge_driver.c +++ b/src/network/bridge_driver.c @@ -341,9 +341,6 @@ networkRunHook(virNetworkObjPtr obj, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</hookData>"); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - xml = virBufferContentAndReset(&buf); hookret = virHookCall(VIR_HOOK_DRIVER_NETWORK, def->name, op, sub_op, NULL, xml, NULL); @@ -1926,9 +1923,6 @@ networkRadvdConfContents(virNetworkObjPtr obj, virBufferAddLit(&configbuf, "};\n"); - if (virBufferCheckError(&configbuf) < 0) - goto cleanup; - *configstr = virBufferContentAndReset(&configbuf); ret = 0; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index 525e71f80c..e3c81057f0 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -304,9 +304,6 @@ udevGenerateDeviceName(struct udev_device *device, if (s != NULL) virBufferAsprintf(&buf, "_%s", s); - if (virBufferCheckError(&buf) < 0) - return -1; - def->name = virBufferContentAndReset(&buf); for (i = 0; i < strlen(def->name); i++) { diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c index 50db150151..aca1b38672 100644 --- a/src/nwfilter/nwfilter_ebiptables_driver.c +++ b/src/nwfilter/nwfilter_ebiptables_driver.c @@ -303,9 +303,6 @@ _printDataType(virNWFilterVarCombIterPtr vars, } } - if (virBufferCheckError(&vb) < 0) - return -1; - flags = virBufferContentAndReset(&vb); if (virStrcpy(buf, flags, bufsize) < 0) { @@ -1559,8 +1556,6 @@ printStateMatchFlags(int32_t flags, char **bufptr) "", flags, false); - if (virBufferCheckError(&buf) < 0) - return -1; *bufptr = virBufferContentAndReset(&buf); return 0; } @@ -2413,9 +2408,6 @@ ebtablesCreateRuleInstance(virFirewallPtr fw, if (ENTRY_WANT_NEG_SIGN(&rule->p.ipv6HdrFilter.dataICMPTypeStart)) virFirewallRuleAddArg(fw, fwrule, "!"); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - r = virBufferContentAndReset(&buf); virFirewallRuleAddArg(fw, fwrule, r); diff --git a/src/nwfilter/nwfilter_gentech_driver.c b/src/nwfilter/nwfilter_gentech_driver.c index 0366deaf8b..6789a4a3fa 100644 --- a/src/nwfilter/nwfilter_gentech_driver.c +++ b/src/nwfilter/nwfilter_gentech_driver.c @@ -180,8 +180,6 @@ virNWFilterPrintVars(virHashTablePtr vars, virHashForEach(vars, printString, &ps); - if (virBufferCheckError(&ps.buf) < 0) - return NULL; return virBufferContentAndReset(&ps.buf); } diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 8b1d804233..a23766bfd9 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -220,8 +220,6 @@ phypExec(LIBSSH2_SESSION *session, const char *cmd, int *exit_status, channel = NULL; VIR_FREE(buffer); - if (virBufferCheckError(&tex_ret) < 0) - return NULL; return virBufferContentAndReset(&tex_ret); err: @@ -242,8 +240,6 @@ phypExecBuffer(LIBSSH2_SESSION *session, virBufferPtr buf, int *exit_status, char *cmd; char *ret; - if (virBufferCheckError(buf) < 0) - return NULL; cmd = virBufferContentAndReset(buf); ret = phypExec(session, cmd, exit_status, conn); VIR_FREE(cmd); diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c78ad56edf..9bb3c96448 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4088,8 +4088,7 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps) virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</qemuCaps>\n"); - if (virBufferCheckError(&buf) == 0) - ret = virBufferContentAndReset(&buf); + ret = virBufferContentAndReset(&buf); return ret; } diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 0160507737..80c31e4d44 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1011,9 +1011,6 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, if (src->path) virBufferAsprintf(&buf, ":exportname=%s", src->path); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } /* NBD code uses URI formatting scheme as others in some cases */ @@ -1090,9 +1087,6 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, if (src->configFile) virBufferEscape(&buf, '\\', ":", ":conf=%s", src->configFile); - if (virBufferCheckError(&buf) < 0) - return NULL; - ret = virBufferContentAndReset(&buf); break; @@ -1862,9 +1856,6 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk, qemuBuildDiskThrottling(disk, &opt); - if (virBufferCheckError(&opt) < 0) - goto error; - return virBufferContentAndReset(&opt); error: @@ -2279,9 +2270,6 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_USB_STORAGE_WERROR)) qemuBuildDiskFrontendAttributeErrorPolicy(disk, &opt); - if (virBufferCheckError(&opt) < 0) - goto error; - return virBufferContentAndReset(&opt); error: @@ -2300,9 +2288,6 @@ qemuBuildZPCIDevStr(virDomainDeviceInfoPtr dev) dev->alias, dev->addr.pci.zpci.uid); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -2643,9 +2628,6 @@ qemuBuildFSStr(virDomainFSDefPtr fs) if (fs->readonly) virBufferAddLit(&opt, ",readonly"); - if (virBufferCheckError(&opt) < 0) - return NULL; - return virBufferContentAndReset(&opt); } @@ -2673,9 +2655,6 @@ qemuBuildFSDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&opt, def, &fs->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&opt) < 0) - return NULL; - return virBufferContentAndReset(&opt); } @@ -3038,9 +3017,6 @@ qemuBuildControllerDevStr(const virDomainDef *domainDef, if (qemuBuildDeviceAddressStr(&buf, domainDef, &def->info, qemuCaps) < 0) return -1; - if (virBufferCheckError(&buf) < 0) - return -1; - *devstr = virBufferContentAndReset(&buf); return 0; } @@ -3693,9 +3669,6 @@ qemuBuildMemoryDeviceStr(virDomainMemoryDefPtr mem, } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -3881,9 +3854,6 @@ qemuBuildNicDevStr(virDomainDefPtr def, qemuBuildVirtioOptionsStr(&buf, net->virtio, qemuCaps) < 0) goto error; - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); error: @@ -4031,8 +4001,6 @@ qemuBuildHostNetStr(virDomainNetDefPtr net, virBufferTrim(&buf, ",", -1); - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -4056,9 +4024,6 @@ qemuBuildWatchdogDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4158,9 +4123,6 @@ qemuBuildNVRAMDevStr(virDomainNVRAMDefPtr dev) return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4248,9 +4210,6 @@ qemuBuildVirtioInputDevStr(const virDomainDef *def, if (qemuBuildVirtioOptionsStr(&buf, dev->virtio, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4282,9 +4241,6 @@ qemuBuildUSBInputDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4389,9 +4345,6 @@ qemuBuildSoundDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &sound->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4606,9 +4559,6 @@ qemuBuildDeviceVideoStr(const virDomainDef *def, if (qemuBuildVirtioOptionsStr(&buf, video->virtio, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4823,9 +4773,6 @@ qemuBuildPCIHostdevDevStr(const virDomainDef *def, if (qemuBuildRomStr(&buf, dev->info) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4856,9 +4803,6 @@ qemuBuildUSBHostdevDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4888,9 +4832,6 @@ qemuBuildHubDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4957,9 +4898,6 @@ qemuBuildSCSIiSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, virBufferAddLit(&buf, ",if=none,format=raw"); } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -4991,9 +4929,6 @@ qemuBuildSCSIVHostHostdevDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -5023,9 +4958,6 @@ qemuBuildSCSIHostdevDrvStr(virDomainHostdevDefPtr dev, if (dev->readonly) virBufferAddLit(&buf, ",readonly=on"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -5084,9 +5016,6 @@ qemuBuildSCSIHostdevDevStr(const virDomainDef *def, if (dev->info->bootIndex) virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -5412,9 +5341,6 @@ qemuBuildChrChardevStr(virLogManagerPtr logManager, return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -5450,9 +5376,6 @@ qemuBuildHostdevMediatedDevStr(const virDomainDef *def, if (dev->info->bootIndex) virBufferAsprintf(&buf, ",bootindex=%u", dev->info->bootIndex); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -5712,8 +5635,6 @@ qemuBuildVirtioSerialPortDevStr(const virDomainDef *def, virBufferAsprintf(&buf, ",name=%s", dev->target.name ? dev->target.name : "com.redhat.spice.0"); } - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -5738,8 +5659,6 @@ qemuBuildSclpDevStr(virDomainChrDefPtr dev) } virBufferAsprintf(&buf, ",chardev=char%s,id=%s", dev->info.alias, dev->info.alias); - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -5870,8 +5789,6 @@ qemuBuildRNGDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -6063,9 +5980,6 @@ qemuBuildSmbiosBaseBoardStr(virSysinfoBaseBoardDefPtr def) virQEMUBuildBufferEscapeComma(&buf, def->location); } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -6124,9 +6038,6 @@ qemuBuildSmbiosChassisStr(virSysinfoChassisDefPtr def) virQEMUBuildBufferEscapeComma(&buf, def->sku); } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -6373,9 +6284,6 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) } } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -6588,9 +6496,6 @@ qemuBuildBootCommandLine(virCommandPtr cmd, virBufferTrim(&boot_buf, ",", -1); - if (virBufferCheckError(&boot_buf) < 0) - return -1; - boot_opts_str = virBufferContentAndReset(&boot_buf); if (boot_opts_str) { virCommandAddArg(cmd, "-boot"); @@ -7015,11 +6920,6 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, virBufferAddLit(&buf, ",l3-cache=off"); } - if (virBufferCheckError(&cpu_buf) < 0) - return -1; - if (virBufferCheckError(&buf) < 0) - return -1; - cpu = virBufferContentAndReset(&cpu_buf); cpu_flags = virBufferContentAndReset(&buf); @@ -7502,9 +7402,6 @@ qemuBuildSmpCommandLine(virCommandPtr cmd, virBufferAsprintf(&buf, ",threads=%u", 1); } - if (virBufferCheckError(&buf) < 0) - return -1; - virCommandAddArgBuffer(cmd, &buf); return 0; } @@ -7853,9 +7750,6 @@ qemuBuildGraphicsSDLCommandLine(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED, } - if (virBufferCheckError(&opt) < 0) - return -1; - virCommandAddArgBuffer(cmd, &opt); return 0; @@ -8266,9 +8160,6 @@ qemuBuildGraphicsEGLHeadlessCommandLine(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED graphics->data.egl_headless.rendernode); } - if (virBufferCheckError(&opt) < 0) - return -1; - virCommandAddArg(cmd, "-display"); virCommandAddArgBuffer(cmd, &opt); @@ -8919,9 +8810,6 @@ qemuBuildShmemDevLegacyStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -8961,9 +8849,6 @@ qemuBuildShmemDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &shmem->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -9491,9 +9376,6 @@ qemuBuildRedirdevDevStr(const virDomainDef *def, if (qemuBuildDeviceAddressStr(&buf, def, &dev->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -9631,9 +9513,6 @@ qemuBuildTPMDevStr(const virDomainDef *def, virBufferAsprintf(&buf, "%s,tpmdev=tpm-%s,id=%s", model, tpm->info.alias, tpm->info.alias); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -9718,9 +9597,6 @@ qemuBuildTPMBackendStr(const virDomainDef *def, return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -10227,9 +10103,6 @@ qemuBuildVsockDevStr(virDomainDefPtr def, if (qemuBuildDeviceAddressStr(&buf, def, &vsock->info, qemuCaps) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -10590,9 +10463,6 @@ qemuBuildSerialChrDeviceStr(char **deviceStr, if (qemuBuildDeviceAddressStr(&buf, def, &serial->info, qemuCaps) < 0) return -1; - if (virBufferCheckError(&buf) < 0) - return -1; - *deviceStr = virBufferContentAndReset(&buf); return 0; } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 1396b28a24..71309d9c83 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -7407,16 +7407,12 @@ qemuDomainChrDefDropDefaultPath(virDomainChrDefPtr chr, virBufferAddLit(&buf, "/([^/]+\\.)|(domain-[^/]+/)"); virBufferEscapeRegex(&buf, "%s$", chr->target.name); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - regexp = virBufferContentAndReset(&buf); if (virStringMatch(chr->source->data.nix.path, regexp)) VIR_FREE(chr->source->data.nix.path); ret = 0; - cleanup: VIR_FREE(regexp); virObjectUnref(cfg); return ret; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index af8cbf40f4..9a2cf54ce2 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1302,8 +1302,6 @@ qemuConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index f625c7086b..27e6bde601 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -877,9 +877,6 @@ qemuMigrationCookieXMLFormatStr(virQEMUDriverPtr driver, return NULL; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 99f55c420a..816fd4bb9b 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -323,9 +323,6 @@ qemuMonitorJSONCommandWithFd(qemuMonitorPtr mon, goto cleanup; virBufferAddLit(&cmdbuf, "\r\n"); - if (virBufferCheckError(&cmdbuf) < 0) - goto cleanup; - msg.txLength = virBufferUse(&cmdbuf); msg.txBuffer = virBufferContentAndReset(&cmdbuf); msg.txFD = scm_fd; diff --git a/src/rpc/virnetlibsshsession.c b/src/rpc/virnetlibsshsession.c index 0b98236f38..c70838398c 100644 --- a/src/rpc/virnetlibsshsession.c +++ b/src/rpc/virnetlibsshsession.c @@ -694,9 +694,6 @@ virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess, if (virBufferUse(&buff) > 0) virBufferAddChar(&buff, '\n'); - if (virBufferCheckError(&buff) < 0) - return -1; - for (iprompt = 0; iprompt < nprompts; ++iprompt) { virConnectCredential retr_passphrase; const char *promptStr; @@ -727,9 +724,6 @@ virNetLibsshAuthenticateKeyboardInteractive(virNetLibsshSessionPtr sess, virBufferAddBuffer(&prompt_buff, &buff); virBufferAdd(&prompt_buff, promptStr, promptStrLen); - if (virBufferCheckError(&prompt_buff) < 0) - goto prompt_error; - prompt = virBufferContentAndReset(&prompt_buff); } else { if (VIR_STRNDUP(prompt, promptStr, promptStrLen) < 0) diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c index 6574ee0d16..d9fa38d5a6 100644 --- a/src/rpc/virnetsocket.c +++ b/src/rpc/virnetsocket.c @@ -898,18 +898,10 @@ int virNetSocketNewConnectSSH(const char *nodename, virCommandAddArgList(cmd, "--", nodename, "sh", "-c", NULL); virBufferEscapeShell(&buf, netcat); - if (virBufferCheckError(&buf) < 0) { - virCommandFree(cmd); - return -1; - } quoted = virBufferContentAndReset(&buf); virBufferEscapeShell(&buf, quoted); VIR_FREE(quoted); - if (virBufferCheckError(&buf) < 0) { - virCommandFree(cmd); - return -1; - } quoted = virBufferContentAndReset(&buf); /* diff --git a/src/rpc/virnetsshsession.c b/src/rpc/virnetsshsession.c index 931c7091cc..199043f408 100644 --- a/src/rpc/virnetsshsession.c +++ b/src/rpc/virnetsshsession.c @@ -359,9 +359,6 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) virBufferAsprintf(&buff, "%02hhX:", keyhash[i]); virBufferTrim(&buff, ":", 1); - if (virBufferCheckError(&buff) < 0) - return -1; - keyhashstr = virBufferContentAndReset(&buff); askKey.type = VIR_CRED_ECHOPROMPT; @@ -424,9 +421,6 @@ virNetSSHCheckHostKey(virNetSSHSessionPtr sess) * to port number */ virBufferAsprintf(&buff, "[%s]:%d", sess->hostname, sess->port); - if (virBufferCheckError(&buff) < 0) - return -1; - hostnameStr = virBufferContentAndReset(&buff); if (libssh2_knownhost_addc(sess->knownHosts, diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c index 1c59c18b0d..7ce26edab0 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -266,9 +266,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, } } - if (virBufferCheckError(&mon_host) < 0) - goto cleanup; - mon_buff = virBufferContentAndReset(&mon_host); if (virStorageBackendRBDRADOSConfSet(ptr->cluster, "mon_host", @@ -1224,9 +1221,6 @@ virStorageBackendRBDCloneImage(rados_ioctx_t io, virBufferAsprintf(&snapname, "libvirt-%d", (int)virRandomInt(65534)); - if (virBufferCheckError(&snapname) < 0) - goto cleanup; - snapname_buff = virBufferContentAndReset(&snapname); if (virStorageBackendRBDSnapshotCreate(image, origvol, snapname_buff) < 0) diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index 7b934b61e0..a3447c453c 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -758,9 +758,6 @@ storageBackendCreateQemuImgOpts(virStorageEncryptionInfoDefPtr encinfo, virBufferTrim(&buf, ",", -1); - if (virBufferCheckError(&buf) < 0) - goto error; - *opts = virBufferContentAndReset(&buf); return 0; @@ -946,11 +943,6 @@ storageBackendCreateQemuImgSecretObject(virCommandPtr cmd, virBufferAsprintf(&buf, "secret,id=%s,file=", secretAlias); virQEMUBuildBufferEscapeComma(&buf, secretPath); - if (virBufferCheckError(&buf) < 0) { - virBufferFreeAndReset(&buf); - return -1; - } - commandStr = virBufferContentAndReset(&buf); virCommandAddArgList(cmd, "--object", commandStr, NULL); @@ -976,11 +968,6 @@ storageBackendResizeQemuImgImageOpts(virCommandPtr cmd, secretAlias); virQEMUBuildBufferEscapeComma(&buf, path); - if (virBufferCheckError(&buf) < 0) { - virBufferFreeAndReset(&buf); - return -1; - } - commandStr = virBufferContentAndReset(&buf); virCommandAddArgList(cmd, "--image-opts", commandStr, NULL); diff --git a/src/util/virbitmap.c b/src/util/virbitmap.c index 80eccaadce..9bdb785025 100644 --- a/src/util/virbitmap.c +++ b/src/util/virbitmap.c @@ -369,7 +369,6 @@ virBitmapToString(virBitmapPtr bitmap, bitmap->map[sz]); } - virBufferCheckError(&buf); ret = virBufferContentAndReset(&buf); if (!ret) return NULL; diff --git a/src/util/virbuffer.c b/src/util/virbuffer.c index b513c59268..1b93110919 100644 --- a/src/util/virbuffer.c +++ b/src/util/virbuffer.c @@ -276,20 +276,6 @@ void virBufferFreeAndReset(virBufferPtr buf) memset(buf, 0, sizeof(*buf)); } -/** - * virBufferCheckErrorInternal: - * @buf: the buffer - * - * Report an error if the buffer is in an error state. - * - * Return -1 if an error has been reported, 0 otherwise. - */ -int -virBufferCheckErrorInternal(const virBuffer *buf G_GNUC_UNUSED) -{ - return 0; -} - /** * virBufferUse: * @buf: the usage of the string in the buffer diff --git a/src/util/virbuffer.h b/src/util/virbuffer.h index c7f0568067..8eb9608c71 100644 --- a/src/util/virbuffer.h +++ b/src/util/virbuffer.h @@ -43,22 +43,9 @@ struct _virBuffer { const char *virBufferCurrentContent(virBufferPtr buf); char *virBufferContentAndReset(virBufferPtr buf); void virBufferFreeAndReset(virBufferPtr buf); -int virBufferCheckErrorInternal(const virBuffer *buf) - ATTRIBUTE_NONNULL(1); G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(virBuffer, virBufferFreeAndReset); -/** - * virBufferCheckError - * - * Checks if the buffer is in error state and reports an error. - * - * Returns 0 if no error has occurred, otherwise an error is reported - * and -1 is returned. - */ -#define virBufferCheckError(buf) \ - virBufferCheckErrorInternal(buf) - size_t virBufferUse(const virBuffer *buf); void virBufferAdd(virBufferPtr buf, const char *str, int len); void virBufferAddBuffer(virBufferPtr buf, virBufferPtr toadd); diff --git a/src/util/vircommand.c b/src/util/vircommand.c index 6baa0b251f..d7fa237caf 100644 --- a/src/util/vircommand.c +++ b/src/util/vircommand.c @@ -2125,9 +2125,6 @@ virCommandToString(virCommandPtr cmd, bool linebreaks) prevopt = (cmd->args[i][0] == '-'); } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/util/virconf.c b/src/util/virconf.c index 3b678015f5..648ff3f7b3 100644 --- a/src/util/virconf.c +++ b/src/util/virconf.c @@ -1445,9 +1445,6 @@ virConfWriteFile(const char *filename, virConfPtr conf) cur = cur->next; } - if (virBufferCheckError(&buf) < 0) - return -1; - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR); if (fd < 0) { virBufferFreeAndReset(&buf); @@ -1498,9 +1495,6 @@ virConfWriteMem(char *memory, int *len, virConfPtr conf) cur = cur->next; } - if (virBufferCheckError(&buf) < 0) - return -1; - use = virBufferUse(&buf); content = virBufferContentAndReset(&buf); diff --git a/src/util/virdnsmasq.c b/src/util/virdnsmasq.c index f22250a07e..964eeb9a43 100644 --- a/src/util/virdnsmasq.c +++ b/src/util/virdnsmasq.c @@ -151,9 +151,6 @@ addnhostsNew(const char *name, virBufferEscapeString(&buf, "/%s", name); virBufferAsprintf(&buf, ".%s", DNSMASQ_ADDNHOSTSFILE_SUFFIX); - if (virBufferCheckError(&buf) < 0) - goto error; - if (!(addnhostsfile->path = virBufferContentAndReset(&buf))) goto error; @@ -365,9 +362,6 @@ hostsfileNew(const char *name, virBufferEscapeString(&buf, "/%s", name); virBufferAsprintf(&buf, ".%s", DNSMASQ_HOSTSFILE_SUFFIX); - if (virBufferCheckError(&buf) < 0) - goto error; - if (!(hostsfile->path = virBufferContentAndReset(&buf))) goto error; return hostsfile; diff --git a/src/util/virfilecache.c b/src/util/virfilecache.c index 8ab37bae4a..aecabf173d 100644 --- a/src/util/virfilecache.c +++ b/src/util/virfilecache.c @@ -118,9 +118,6 @@ virFileCacheGetFileName(virFileCachePtr cache, if (cache->suffix) virBufferAsprintf(&buf, ".%s", cache->suffix); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitch.c index 1d2bbf9dd7..8607cf48e6 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -107,15 +107,12 @@ virNetDevOpenvswitchConstructVlans(virCommandPtr cmd, virNetDevVlanPtr virtVlan) virBufferAsprintf(&buf, "%d", virtVlan->tag[i]); } - if (virBufferCheckError(&buf) < 0) - goto cleanup; virCommandAddArg(cmd, virBufferCurrentContent(&buf)); } else if (virtVlan->nTags) { virCommandAddArgFormat(cmd, "tag=%d", virtVlan->tag[0]); } ret = 0; - cleanup: virBufferFreeAndReset(&buf); return ret; } diff --git a/src/util/virpidfile.c b/src/util/virpidfile.c index f7849d91a6..2acdcaa954 100644 --- a/src/util/virpidfile.c +++ b/src/util/virpidfile.c @@ -50,14 +50,7 @@ char *virPidFileBuildPath(const char *dir, const char* name) virBufferAsprintf(&buf, "%s", dir); virBufferEscapeString(&buf, "/%s.pid", name); - if (virBufferCheckError(&buf) < 0) - goto error; - return virBufferContentAndReset(&buf); - - error: - virBufferFreeAndReset(&buf); - return NULL; } diff --git a/src/util/virqemu.c b/src/util/virqemu.c index 162c3c603f..37ca1af8a4 100644 --- a/src/util/virqemu.c +++ b/src/util/virqemu.c @@ -274,9 +274,6 @@ virQEMUBuildDriveCommandlineFromJSON(virJSONValuePtr srcdef) virQEMUBuildCommandLineJSONArrayNumbered) < 0) goto cleanup; - if (virBufferCheckError(&buf) < 0) - goto cleanup; - ret = virBufferContentAndReset(&buf); cleanup: diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c index 29ea52a16f..43dbbf6ab9 100644 --- a/src/util/virresctrl.c +++ b/src/util/virresctrl.c @@ -1437,7 +1437,7 @@ virResctrlAllocMemoryBandwidthFormat(virResctrlAllocPtr alloc, virBufferTrim(buf, ";", 1); virBufferAddChar(buf, '\n'); - return virBufferCheckError(buf); + return 0; } @@ -1582,7 +1582,7 @@ virResctrlAllocFormatCache(virResctrlAllocPtr alloc, } } - return virBufferCheckError(buf); + return 0; } diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index be2b5479bb..f32194adbc 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -3956,9 +3956,6 @@ virStorageFileCanonicalizeFormatPath(char **components, virBufferAdd(&buf, components[i], -1); } - if (virBufferCheckError(&buf) < 0) - return NULL; - /* if the output string is empty just return an empty string */ if (!(ret = virBufferContentAndReset(&buf))) ret = g_strdup(""); diff --git a/src/util/virstring.c b/src/util/virstring.c index 52e36fe4da..a728c74efb 100644 --- a/src/util/virstring.c +++ b/src/util/virstring.c @@ -155,8 +155,6 @@ char *virStringListJoin(const char **strings, virBufferAdd(&buf, delim, -1); strings++; } - if (virBufferCheckError(&buf) < 0) - return NULL; ret = virBufferContentAndReset(&buf); if (!ret) ret = g_strdup(""); @@ -1197,9 +1195,6 @@ virStringReplace(const char *haystack, tmp1 = tmp2; } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 6e7e221f00..0714661237 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -1510,9 +1510,6 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) return -1; } - if (virBufferCheckError(buf) < 0) - return -1; - return 0; } diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c index 2ff0341b11..7ca0bb10fd 100644 --- a/src/util/virsystemd.c +++ b/src/util/virsystemd.c @@ -116,9 +116,6 @@ char *virSystemdMakeScopeName(const char *name, virSystemdEscapeName(&buf, name); virBufferAddLit(&buf, ".scope"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } @@ -133,9 +130,6 @@ char *virSystemdMakeSliceName(const char *partition) virSystemdEscapeName(&buf, partition); virBufferAddLit(&buf, ".slice"); - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/util/viruri.c b/src/util/viruri.c index 3532fa5576..1c060f964e 100644 --- a/src/util/viruri.c +++ b/src/util/viruri.c @@ -275,9 +275,6 @@ char *virURIFormatParams(virURIPtr uri) } } - if (virBufferCheckError(&buf) < 0) - return NULL; - return virBufferContentAndReset(&buf); } diff --git a/src/util/virxml.c b/src/util/virxml.c index f4c9bc89e5..31e7bb3c73 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1387,10 +1387,6 @@ virXMLFormatElement(virBufferPtr buf, return 0; } - if ((attrBuf && virBufferCheckError(attrBuf) < 0) || - (childBuf && virBufferCheckError(childBuf) < 0)) - goto cleanup; - virBufferAsprintf(buf, "<%s", name); if (attrBuf && virBufferUse(attrBuf) > 0) @@ -1406,7 +1402,6 @@ virXMLFormatElement(virBufferPtr buf, ret = 0; - cleanup: virBufferFreeAndReset(attrBuf); virBufferFreeAndReset(childBuf); return ret; diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 0d1d87bac6..e0b06accf5 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -3432,9 +3432,6 @@ virVMXFormatConfig(virVMXContext *ctx, virDomainXMLOptionPtr xmlopt, virDomainDe } /* Get final VMX output */ - if (virBufferCheckError(&buffer) < 0) - goto cleanup; - vmx = virBufferContentAndReset(&buffer); cleanup: diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 5b54f83b22..c5015be074 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -460,8 +460,6 @@ vzConnectGetSysinfo(virConnectPtr conn, unsigned int flags) if (virSysinfoFormat(&buf, driver->hostsysinfo) < 0) return NULL; - if (virBufferCheckError(&buf) < 0) - return NULL; return virBufferContentAndReset(&buf); } @@ -2783,9 +2781,6 @@ vzBakeCookie(vzDriverPtr driver, virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</vz-migration>\n"); - if (virBufferCheckError(&buf) < 0) - return -1; - *cookieout = virBufferContentAndReset(&buf); *cookieoutlen = strlen(*cookieout) + 1; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index 5f89d73c72..ae7eefc5ef 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -330,9 +330,6 @@ testQemuDiskXMLToPropsValidateFile(const void *opaque) VIR_FREE(jsonstr); } - if (virBufferCheckError(&buf) < 0) - goto cleanup; - actual = virBufferContentAndReset(&buf); ret = virTestCompareToFile(actual, jsonpath); @@ -501,9 +498,6 @@ testQemuDiskXMLToPropsValidateFileSrcOnly(const void *opaque) virBufferAdd(&buf, jsonstr, -1); } - if (virBufferCheckError(&buf) < 0) - return -1; - actual = virBufferContentAndReset(&buf); return virTestCompareToFile(actual, jsonpath); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index c0eee921cf..dce4fb3ed3 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -2836,9 +2836,6 @@ testBlockNodeNameDetect(const void *opaque) virBufferTrim(&buf, "\n", -1); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - actual = virBufferContentAndReset(&buf); if (virTestCompareToFile(actual, resultFile) < 0) @@ -2984,9 +2981,6 @@ testQueryJobs(const void *opaque) virBufferTrim(&buf, "\n", -1); - if (virBufferCheckError(&buf) < 0) - goto cleanup; - actual = virBufferContentAndReset(&buf); if (virTestCompareToFile(actual, filenameResult) < 0) diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c index fb76bf185d..828567028e 100644 --- a/tests/qemumonitortestutils.c +++ b/tests/qemumonitortestutils.c @@ -131,8 +131,6 @@ qemuMonitorTestAddErrorResponse(qemuMonitorTestPtr test, usermsg = "unexpected command"; virBufferEscape(&buf, '\\', "\"", "%s", usermsg); - if (virBufferCheckError(&buf) < 0) - return -1; escapemsg = virBufferContentAndReset(&buf); /* replace newline/carriage return with space */ diff --git a/tests/vircgrouptest.c b/tests/vircgrouptest.c index cec07580ac..6833cb3bb0 100644 --- a/tests/vircgrouptest.c +++ b/tests/vircgrouptest.c @@ -210,8 +210,6 @@ testCgroupDetectMounts(const void *args) } virBufferAsprintf(&buf, "%-12s %s\n", "unified", NULLSTR(group->unified.mountPoint)); - if (virBufferCheckError(&buf) < 0) - goto cleanup; actual = virBufferCurrentContent(&buf); if (virTestCompareToFile(actual, parsed) < 0) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ae7777df09..da0cf825ca 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2417,8 +2417,6 @@ cmdBlockcopy(vshControl *ctl, const vshCmd *cmd) virBufferEscapeString(&buf, "<driver type='%s'/>\n", format); virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "</disk>\n"); - if (virBufferCheckError(&buf) < 0) - goto cleanup; xmlstr = virBufferContentAndReset(&buf); } diff --git a/tools/vsh.c b/tools/vsh.c index 5bab5b5c83..2de6e9f915 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -3467,9 +3467,6 @@ cmdComplete(vshControl *ctl, const vshCmd *cmd) arg = opt->data; } - if (virBufferCheckError(&buf) < 0) - goto cleanup; - vshReadlineInit(ctl); if (!(rl_line_buffer = virBufferContentAndReset(&buf))) -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:36PM +0200, Peter Krempa wrote:
The function now never returned an error so we can drop it fully.
now does not return
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/bhyve/bhyve_command.c | 3 - src/bhyve/bhyve_driver.c | 5 - src/conf/capabilities.c | 16 --- src/conf/checkpoint_conf.c | 3 - src/conf/cpu_conf.c | 7 -- src/conf/domain_addr.c | 2 - src/conf/domain_capabilities.c | 1 - src/conf/domain_conf.c | 38 ------- src/conf/interface_conf.c | 3 - src/conf/network_conf.c | 3 - src/conf/node_device_conf.c | 3 - src/conf/nwfilter_conf.c | 9 -- src/conf/secret_conf.c | 3 - src/conf/snapshot_conf.c | 3 - src/conf/storage_conf.c | 12 -- src/conf/virnetworkobj.c | 3 - src/conf/virnetworkportdef.c | 3 - src/conf/virnwfilterbindingdef.c | 3 - src/conf/virnwfilterbindingobj.c | 3 - src/conf/virsavecookie.c | 3 - src/cpu/cpu_map.c | 2 - src/cpu/cpu_x86.c | 10 -- src/esx/esx_driver.c | 12 -- src/esx/esx_util.c | 6 - src/esx/esx_vi.c | 15 --- src/esx/esx_vi_methods.c | 3 - src/hyperv/hyperv_driver.c | 3 - src/hyperv/hyperv_wmi.c | 10 -- src/libvirt_private.syms | 1 - src/libxl/libxl_conf.c | 5 - src/libxl/libxl_driver.c | 2 - src/libxl/libxl_migration.c | 3 - src/libxl/xen_common.c | 13 --- src/libxl/xen_xl.c | 9 -- src/libxl/xen_xm.c | 3 - src/locking/lock_driver_sanlock.c | 3 - src/lxc/lxc_container.c | 3 - src/lxc/lxc_controller.c | 3 - src/lxc/lxc_driver.c | 2 - src/lxc/lxc_fuse.c | 4 - src/network/bridge_driver.c | 6 - src/node_device/node_device_udev.c | 3 - src/nwfilter/nwfilter_ebiptables_driver.c | 8 -- src/nwfilter/nwfilter_gentech_driver.c | 2 - src/phyp/phyp_driver.c | 4 - src/qemu/qemu_capabilities.c | 3 +- src/qemu/qemu_command.c | 130 ---------------------- src/qemu/qemu_domain.c | 4 - src/qemu/qemu_driver.c | 2 - src/qemu/qemu_migration_cookie.c | 3 - src/qemu/qemu_monitor_json.c | 3 - src/rpc/virnetlibsshsession.c | 6 - src/rpc/virnetsocket.c | 8 -- src/rpc/virnetsshsession.c | 6 - src/storage/storage_backend_rbd.c | 6 - src/storage/storage_util.c | 13 --- src/util/virbitmap.c | 1 - src/util/virbuffer.c | 14 --- src/util/virbuffer.h | 13 --- src/util/vircommand.c | 3 - src/util/virconf.c | 6 - src/util/virdnsmasq.c | 6 - src/util/virfilecache.c | 3 - src/util/virnetdevopenvswitch.c | 3 - src/util/virpidfile.c | 7 -- src/util/virqemu.c | 3 - src/util/virresctrl.c | 4 +- src/util/virstoragefile.c | 3 - src/util/virstring.c | 5 - src/util/virsysinfo.c | 3 - src/util/virsystemd.c | 6 - src/util/viruri.c | 3 - src/util/virxml.c | 5 - src/vmx/vmx.c | 3 - src/vz/vz_driver.c | 5 - tests/qemublocktest.c | 6 - tests/qemumonitorjsontest.c | 6 - tests/qemumonitortestutils.c | 2 - tests/vircgrouptest.c | 2 - tools/virsh-domain.c | 2 - tools/vsh.c | 3 - 81 files changed, 3 insertions(+), 559 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Now that we don't have to deal with errors of virBuffer we can also make this function void. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 112 +++++++++++++++++++---------------------- src/qemu/qemu_domain.c | 24 ++++----- src/util/virsysinfo.c | 5 +- src/util/virxml.c | 14 ++---- src/util/virxml.h | 5 +- 5 files changed, 69 insertions(+), 91 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 778858fe3e..5d45cb23a9 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7254,8 +7254,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf, break; } - if (virXMLFormatElement(buf, "address", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "address", &attrBuf, &childBuf); ret = 0; @@ -24126,8 +24125,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf, if (xmlopt->privateData.storageFormat(src, &childBuf) < 0) goto cleanup; - if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "privateData", NULL, &childBuf); ret = 0; @@ -24233,8 +24231,7 @@ virDomainDiskSourceFormat(virBufferPtr buf, if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0) return -1; - if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0) - return -1; + virXMLFormatElement(buf, element, &attrBuf, &childBuf); return 0; } @@ -24286,8 +24283,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, flags) < 0) return -1; - if (virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf) < 0) - return -1; + virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf); return 0; } @@ -24338,7 +24334,9 @@ virDomainDiskDefFormatIotune(virBufferPtr buf, FORMAT_IOTUNE(read_iops_sec_max_length); FORMAT_IOTUNE(write_iops_sec_max_length); - return virXMLFormatElement(buf, "iotune", NULL, &childBuf); + virXMLFormatElement(buf, "iotune", NULL, &childBuf); + + return 0; } #undef FORMAT_IOTUNE @@ -24400,7 +24398,8 @@ virDomainDiskDefFormatDriver(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, disk->virtio); - return virXMLFormatElement(buf, "driver", &driverBuf, NULL); + virXMLFormatElement(buf, "driver", &driverBuf, NULL); + return 0; } @@ -24450,8 +24449,7 @@ virDomainDiskDefFormatMirror(virBufferPtr buf, if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, flags) < 0) return -1; - if (virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf) < 0) - return -1; + virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf); return 0; } @@ -24475,7 +24473,8 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf, if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0) return -1; - return virXMLFormatElement(buf, "privateData", NULL, &childBuf); + virXMLFormatElement(buf, "privateData", NULL, &childBuf); + return 0; } @@ -24633,7 +24632,9 @@ virDomainControllerDriverFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverBuf, def->virtio); - return virXMLFormatElement(buf, "driver", &driverBuf, NULL); + virXMLFormatElement(buf, "driver", &driverBuf, NULL); + + return 0; } @@ -24785,7 +24786,9 @@ virDomainControllerDefFormat(virBufferPtr buf, "pcihole64>\n", def->opts.pciopts.pcihole64size); } - return virXMLFormatElement(buf, "controller", &attrBuf, &childBuf); + virXMLFormatElement(buf, "controller", &attrBuf, &childBuf); + + return 0; } @@ -25628,8 +25631,7 @@ virDomainNetDefFormat(virBufferPtr buf, virTristateBoolTypeToString(def->managed_tap)); } - if (virXMLFormatElement(buf, "target", &attrBuf, NULL) < 0) - return -1; + virXMLFormatElement(buf, "target", &attrBuf, NULL); if (def->ifname_guest || def->ifname_guest_actual) { virBufferAddLit(buf, "<guest"); @@ -25778,8 +25780,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels, def->seclabels, flags); - if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) - goto error; + virXMLFormatElement(buf, "source", &attrBuf, &childBuf); } break; @@ -25822,8 +25823,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceReconnectDefFormat(&childBuf, &def->data.tcp.reconnect); - if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) - goto error; + virXMLFormatElement(buf, "source", &attrBuf, &childBuf); virBufferAsprintf(buf, "<protocol type='%s'/>\n", virDomainChrTcpProtocolTypeToString( @@ -25841,8 +25841,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, virDomainChrSourceReconnectDefFormat(&childBuf, &def->data.nix.reconnect); - if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) - goto error; + virXMLFormatElement(buf, "source", &attrBuf, &childBuf); } break; @@ -25863,9 +25862,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf, } return 0; - - error: - return -1; } @@ -26229,10 +26225,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) < 0) - return -1; + virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL); + virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf); - return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf); + return 0; } static int @@ -26281,7 +26277,9 @@ virDomainWatchdogDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) return -1; - return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf); + virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf); + + return 0; } static int virDomainPanicDefFormat(virBufferPtr buf, @@ -26298,7 +26296,9 @@ static int virDomainPanicDefFormat(virBufferPtr buf, if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) return -1; - return virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf); + virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf); + + return 0; } static int @@ -26381,8 +26381,7 @@ virDomainRNGDefFormat(virBufferPtr buf, virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - if (virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL) < 0) - return -1; + virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) return -1; @@ -26664,14 +26663,15 @@ virDomainInputDefFormat(virBufferPtr buf, virBufferSetChildIndent(&childBuf, buf); virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); - if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0) - return -1; + virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); virBufferEscapeString(&childBuf, "<source evdev='%s'/>\n", def->source.evdev); if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) return -1; - return virXMLFormatElement(buf, "input", &attrBuf, &childBuf); + virXMLFormatElement(buf, "input", &attrBuf, &childBuf); + + return 0; } @@ -27373,7 +27373,9 @@ virDomainHubDefFormat(virBufferPtr buf, virBufferAsprintf(&attrBuf, " type='%s'", type); - return virXMLFormatElement(buf, "hub", &attrBuf, &childBuf); + virXMLFormatElement(buf, "hub", &attrBuf, &childBuf); + + return 0; } @@ -27944,18 +27946,15 @@ virDomainIOMMUDefFormat(virBufferPtr buf, virTristateSwitchTypeToString(iommu->iotlb)); } - if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0) - goto cleanup; + virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); virBufferAsprintf(&attrBuf, " model='%s'", virDomainIOMMUModelTypeToString(iommu->model)); - if (virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf); ret = 0; - cleanup: return ret; } @@ -27990,8 +27989,7 @@ virDomainMemtuneFormat(virBufferPtr buf, mem->swap_hard_limit); } - if (virXMLFormatElement(buf, "memtune", NULL, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "memtune", NULL, &childBuf); virBufferSetChildIndent(&childBuf, buf); @@ -28013,11 +28011,9 @@ virDomainMemtuneFormat(virBufferPtr buf, if (mem->discard) virBufferAddLit(&childBuf, "<discard/>\n"); - if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf); ret = 0; - cleanup: return ret; } @@ -28044,14 +28040,12 @@ virDomainVsockDefFormat(virBufferPtr buf, } if (vsock->guest_cid != 0) virBufferAsprintf(&cidAttrBuf, " address='%u'", vsock->guest_cid); - if (virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL) < 0) - goto cleanup; + virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL); if (virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0) < 0) goto cleanup; - if (virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf); ret = 0; @@ -28101,7 +28095,9 @@ virDomainDefFormatBlkiotune(virBufferPtr buf, virBufferAddLit(&childrenBuf, "</device>\n"); } - return virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf); + virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf); + + return 0; } @@ -28187,8 +28183,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, unit, short_size); } - if (virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf) < 0) - return -1; + virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf); break; @@ -28319,8 +28314,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, virBufferAsprintf(&tmpAttrBuf, " policy='%s'", virDomainCapabilitiesPolicyTypeToString(def->features[i])); - if (virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf) < 0) - return -1; + virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf); break; case VIR_DOMAIN_FEATURE_GIC: @@ -28357,8 +28351,7 @@ virDomainDefFormatFeatures(virBufferPtr buf, def->hpt_maxpagesize); } - if (virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf) < 0) - return -1; + virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf); break; case VIR_DOMAIN_FEATURE_MSRS: @@ -28375,7 +28368,8 @@ virDomainDefFormatFeatures(virBufferPtr buf, } } - return virXMLFormatElement(buf, "features", NULL, &childBuf); + virXMLFormatElement(buf, "features", NULL, &childBuf); + return 0; } int diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 71309d9c83..667cc89072 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2327,8 +2327,7 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src, if (src->tlsAlias) virBufferAsprintf(&tmp, "<TLSx509 alias='%s'/>\n", src->tlsAlias); - if (virXMLFormatElement(buf, "objects", NULL, &tmp) < 0) - goto cleanup; + virXMLFormatElement(buf, "objects", NULL, &tmp); ret = 0; @@ -2461,8 +2460,7 @@ qemuDomainObjPrivateXMLFormatBlockjobFormatSource(virBufferPtr buf, virDomainDiskBackingStoreFormat(&childBuf, src, xmlopt, xmlflags) < 0) return -1; - if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0) - return -1; + virXMLFormatElement(buf, element, &attrBuf, &childBuf); return 0; } @@ -2515,8 +2513,7 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload, true) < 0) return -1; - if (virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf) < 0) - return -1; + virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf); } switch ((qemuBlockJobType) job->type) { @@ -2559,7 +2556,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload, break; } - return virXMLFormatElement(data->buf, "blockjob", &attrBuf, &childBuf); + virXMLFormatElement(data->buf, "blockjob", &attrBuf, &childBuf); + return 0; } @@ -2585,7 +2583,8 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf, &iterdata) < 0) return -1; - return virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf); + virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf); + return 0; } @@ -2627,8 +2626,7 @@ qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf, VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < 0) goto cleanup; - if (virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf); ret = 0; @@ -2664,8 +2662,7 @@ qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf, priv->driver->xmlopt) < 0) goto cleanup; - if (virXMLFormatElement(buf, "disk", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "disk", &attrBuf, &childBuf); } ret = 0; @@ -2714,8 +2711,7 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf, if (priv->job.migParams) qemuMigrationParamsFormat(&childBuf, priv->job.migParams); - if (virXMLFormatElement(buf, "job", &attrBuf, &childBuf) < 0) - goto cleanup; + virXMLFormatElement(buf, "job", &attrBuf, &childBuf); ret = 0; diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c index 0714661237..9d013067fe 100644 --- a/src/util/virsysinfo.c +++ b/src/util/virsysinfo.c @@ -1505,10 +1505,7 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def) virBufferAsprintf(&attrBuf, " type='%s'", type); - if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) { - virBufferFreeAndReset(buf); - return -1; - } + virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf); return 0; } diff --git a/src/util/virxml.c b/src/util/virxml.c index 31e7bb3c73..0e66d1623b 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1371,21 +1371,16 @@ virXMLValidatorFree(virXMLValidatorPtr validator) * formatted. * * Both passed buffers are always consumed and freed. - * - * Returns 0 on success, -1 on error. */ -int +void virXMLFormatElement(virBufferPtr buf, const char *name, virBufferPtr attrBuf, virBufferPtr childBuf) { - int ret = -1; - if ((!attrBuf || virBufferUse(attrBuf) == 0) && - (!childBuf || virBufferUse(childBuf) == 0)) { - return 0; - } + (!childBuf || virBufferUse(childBuf) == 0)) + return; virBufferAsprintf(buf, "<%s", name); @@ -1400,11 +1395,8 @@ virXMLFormatElement(virBufferPtr buf, virBufferAddLit(buf, "/>\n"); } - ret = 0; - virBufferFreeAndReset(attrBuf); virBufferFreeAndReset(childBuf); - return ret; } diff --git a/src/util/virxml.h b/src/util/virxml.h index dfdc1f73c3..26ab9f9c2d 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -215,12 +215,11 @@ virXMLValidateAgainstSchema(const char *schemafile, void virXMLValidatorFree(virXMLValidatorPtr validator); -int +void virXMLFormatElement(virBufferPtr buf, const char *name, virBufferPtr attrBuf, - virBufferPtr childBuf) - G_GNUC_WARN_UNUSED_RESULT; + virBufferPtr childBuf); struct _virXPathContextNodeSave { xmlXPathContextPtr ctxt; -- 2.21.0

On Thu, Oct 24, 2019 at 03:56:37PM +0200, Peter Krempa wrote:
Now that we don't have to deal with errors of virBuffer we can also make this function void.
Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/conf/domain_conf.c | 112 +++++++++++++++++++---------------------- src/qemu/qemu_domain.c | 24 ++++----- src/util/virsysinfo.c | 5 +- src/util/virxml.c | 14 ++---- src/util/virxml.h | 5 +- 5 files changed, 69 insertions(+), 91 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Jonathon Jongsma
-
Ján Tomko
-
Peter Krempa