Drop checks for virURIFormat() retval

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@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Michal Privoznik 2023-02-03 15:38:03 +01:00
parent 65b9d9a619
commit 77d417d9ef
8 changed files with 7 additions and 29 deletions

View File

@ -427,17 +427,13 @@ virAdmConnectIsAlive(virAdmConnectPtr conn)
char * char *
virAdmConnectGetURI(virAdmConnectPtr conn) virAdmConnectGetURI(virAdmConnectPtr conn)
{ {
char *uri = NULL;
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("conn=%p", conn);
virResetLastError(); virResetLastError();
virCheckAdmConnectReturn(conn, NULL); virCheckAdmConnectReturn(conn, NULL);
if (!(uri = virURIFormat(conn->uri))) return virURIFormat(conn->uri);
virDispatchError(NULL);
return uri;
} }
/** /**

View File

@ -313,21 +313,13 @@ virConnectGetHostname(virConnectPtr conn)
char * char *
virConnectGetURI(virConnectPtr conn) virConnectGetURI(virConnectPtr conn)
{ {
char *name;
VIR_DEBUG("conn=%p", conn); VIR_DEBUG("conn=%p", conn);
virResetLastError(); virResetLastError();
virCheckConnectReturn(conn, NULL); virCheckConnectReturn(conn, NULL);
if (!(name = virURIFormat(conn->uri))) return virURIFormat(conn->uri);
goto error;
return name;
error:
virDispatchError(conn);
return NULL;
} }

View File

@ -407,8 +407,7 @@ qemuBlockStorageSourceGetCURLProps(virStorageSource *src,
if (!(uri = qemuBlockStorageSourceGetURI(src))) if (!(uri = qemuBlockStorageSourceGetURI(src)))
return NULL; return NULL;
if (!(uristr = virURIFormat(uri))) uristr = virURIFormat(uri);
return NULL;
if (!onlytarget) { if (!onlytarget) {
if (src->auth) { if (src->auth) {

View File

@ -3777,8 +3777,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriver *driver,
/* Send well-formed URI only if uri_in was well-formed */ /* Send well-formed URI only if uri_in was well-formed */
if (well_formed_uri) { if (well_formed_uri) {
uri->port = port; uri->port = port;
if (!(*uri_out = virURIFormat(uri))) *uri_out = virURIFormat(uri);
goto cleanup;
} else { } else {
*uri_out = g_strdup_printf("%s:%d", uri_in, port); *uri_out = g_strdup_printf("%s:%d", uri_in, port);
} }

View File

@ -843,9 +843,6 @@ doRemoteOpen(virConnectPtr conn,
name = virURIFormat(&tmpuri); name = virURIFormat(&tmpuri);
VIR_FREE(tmpuri.query); VIR_FREE(tmpuri.query);
if (!name)
goto failed;
} }
} }
} else { } else {

View File

@ -195,11 +195,7 @@ virStorageBackendGlusterSetMetadata(virStorageBackendGlusterState *state,
tmp = state->uri->path; tmp = state->uri->path;
state->uri->path = g_strdup_printf("/%s", path); state->uri->path = g_strdup_printf("/%s", path);
if (!(vol->target.path = virURIFormat(state->uri))) { vol->target.path = virURIFormat(state->uri);
VIR_FREE(state->uri->path);
state->uri->path = tmp;
return -1;
}
VIR_FREE(state->uri->path); VIR_FREE(state->uri->path);
state->uri->path = tmp; state->uri->path = tmp;

View File

@ -194,7 +194,7 @@ virURIParse(const char *uri)
* Wrapper for xmlSaveUri * Wrapper for xmlSaveUri
* *
* This function constructs back everything that @ref virURIParse * 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 * @returns the constructed uri as a string
*/ */

View File

@ -118,8 +118,7 @@ static int testURIParse(const void *args)
VIR_FREE(uri->query); VIR_FREE(uri->query);
uri->query = virURIFormatParams(uri); uri->query = virURIFormatParams(uri);
if (!(uristr = virURIFormat(uri))) uristr = virURIFormat(uri);
return -1;
if (STRNEQ(uristr, data->uri_out)) { if (STRNEQ(uristr, data->uri_out)) {
VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'", VIR_TEST_DEBUG("URI did not roundtrip, expect '%s', actual '%s'",