[PATCH 02/10] Drop checks for virURIFormat() retval

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The virURIFormat() function either returns a string, or aborts
(on OOM). There's no way this function can return NULL (as of
v7.2.0-rc1~277). Therefore, it doesn't make sense to check its
retval against NULL.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/admin/libvirt-admin.c             |  6 +-----
 src/libvirt-host.c                    | 10 +---------
 src/qemu/qemu_block.c                 |  3 +--
 src/qemu/qemu_migration.c             |  3 +--
 src/remote/remote_driver.c            |  3 ---
 src/storage/storage_backend_gluster.c |  6 +-----
 src/util/viruri.c                     |  2 +-
 tests/viruritest.c                    |  3 +--
 8 files changed, 7 insertions(+), 29 deletions(-)

diff --git a/src/admin/libvirt-admin.c b/src/admin/libvirt-admin.c
index 6baaea4ff2..1786a283e5 100644
--- a/src/admin/libvirt-admin.c
+++ b/src/admin/libvirt-admin.c
@@ -427,17 +427,13 @@ virAdmConnectIsAlive(virAdmConnectPtr conn)
 char *
 virAdmConnectGetURI(virAdmConnectPtr conn)
 {
-    char *uri = NULL;
     VIR_DEBUG("conn=%p", conn);
 
     virResetLastError();
 
     virCheckAdmConnectReturn(conn, NULL);
 
-    if (!(uri = virURIFormat(conn->uri)))
-        virDispatchError(NULL);
-
-    return uri;
+    return virURIFormat(conn->uri);
 }
 
 /**
diff --git a/src/libvirt-host.c b/src/libvirt-host.c
index c02222346c..a2ba347d54 100644
--- a/src/libvirt-host.c
+++ b/src/libvirt-host.c
@@ -313,21 +313,13 @@ virConnectGetHostname(virConnectPtr conn)
 char *
 virConnectGetURI(virConnectPtr conn)
 {
-    char *name;
     VIR_DEBUG("conn=%p", conn);
 
     virResetLastError();
 
     virCheckConnectReturn(conn, NULL);
 
-    if (!(name = virURIFormat(conn->uri)))
-        goto error;
-
-    return name;
-
- error:
-    virDispatchError(conn);
-    return NULL;
+    return virURIFormat(conn->uri);
 }
 
 
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index c218262691..4c06565e0f 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -407,8 +407,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSource *src,
     if (!(uri = qemuBlockStorageSourceGetURI(src)))
         return NULL;
 
-    if (!(uristr = virURIFormat(uri)))
-        return NULL;
+    uristr = virURIFormat(uri);
 
     if (!onlytarget) {
         if (src->auth) {
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index f36bb49be5..2720f0b083 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -3777,8 +3777,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriver *driver,
                 /* Send well-formed URI only if uri_in was well-formed */
                 if (well_formed_uri) {
                     uri->port = port;
-                    if (!(*uri_out = virURIFormat(uri)))
-                        goto cleanup;
+                    *uri_out = virURIFormat(uri);
                 } else {
                     *uri_out = g_strdup_printf("%s:%d", uri_in, port);
                 }
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 9fc73f6d88..2e08ff246f 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -843,9 +843,6 @@ doRemoteOpen(virConnectPtr conn,
                 name = virURIFormat(&tmpuri);
 
                 VIR_FREE(tmpuri.query);
-
-                if (!name)
-                    goto failed;
             }
         }
     } else {
diff --git a/src/storage/storage_backend_gluster.c b/src/storage/storage_backend_gluster.c
index 1fe21b4a2b..bdf91e8bd5 100644
--- a/src/storage/storage_backend_gluster.c
+++ b/src/storage/storage_backend_gluster.c
@@ -195,11 +195,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterState *state,
 
     tmp = state->uri->path;
     state->uri->path = g_strdup_printf("/%s", path);
-    if (!(vol->target.path = virURIFormat(state->uri))) {
-        VIR_FREE(state->uri->path);
-        state->uri->path = tmp;
-        return -1;
-    }
+    vol->target.path = virURIFormat(state->uri);
     VIR_FREE(state->uri->path);
     state->uri->path = tmp;
 
diff --git a/src/util/viruri.c b/src/util/viruri.c
index 53f85ed705..79492e87ce 100644
--- a/src/util/viruri.c
+++ b/src/util/viruri.c
@@ -194,7 +194,7 @@ virURIParse(const char *uri)
  * Wrapper for xmlSaveUri
  *
  * This function constructs back everything that @ref virURIParse
- * changes after parsing
+ * changes after parsing. It aborts on error.
  *
  * @returns the constructed uri as a string
  */
diff --git a/tests/viruritest.c b/tests/viruritest.c
index cd6ce57371..705e0d5c6e 100644
--- a/tests/viruritest.c
+++ b/tests/viruritest.c
@@ -118,8 +118,7 @@ static int testURIParse(const void *args)
     VIR_FREE(uri->query);
     uri->query = virURIFormatParams(uri);
 
-    if (!(uristr = virURIFormat(uri)))
-        return -1;
+    uristr = virURIFormat(uri);
 
     if (STRNEQ(uristr, data->uri_out)) {
         VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'",
-- 
2.39.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux