[PATCH 32/33] virVMXConvertToUTF8: Report non-OOM error on failure of xmlBufferCreateStatic

Peter Krempa pkrempa at redhat.com
Wed Feb 24 16:17:07 UTC 2021


The function has also non-OOM failure case when the passed string has 0
length, so reporting OOM error is not correct.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/vmx/vmx.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index e6c0900a65..73bf7c4f3d 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -781,12 +781,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
         return NULL;
     }

-    if (!(input = xmlBufferCreateStatic((char *)string, strlen(string)))) {
-        virReportOOMError();
-        goto cleanup;
-    }
-
-    if (xmlCharEncInFunc(handler, utf8, input) < 0) {
+    if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) ||
+        xmlCharEncInFunc(handler, utf8, input) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Could not convert from %s to UTF-8 encoding"), encoding);
         goto cleanup;
-- 
2.29.2




More information about the libvir-list mailing list