[libvirt] [PATCH 0/2] util: uri: use unsigned numbers for port

Peter Krempa (2): qemu: command: Remove qemuNetworkDriveGetPort util: uri: Convert port number to unsigned integer src/qemu/qemu_command.c | 22 +++++----------------- src/util/viruri.h | 2 +- 2 files changed, 6 insertions(+), 18 deletions(-) -- 2.13.2

Now that the function is only parsing the string to a number, move it's contents to the only caller. --- src/qemu/qemu_command.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 6ac26af3e..b994940a2 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -491,22 +491,6 @@ qemuSafeSerialParamValue(const char *value) } -static int -qemuNetworkDriveGetPort(const char *port) -{ - int ret = 0; - - if (virStrToLong_i(port, NULL, 10, &ret) < 0 || ret < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("failed to parse port number '%s'"), - port); - return -1; - } - - return ret; -} - - /** * qemuBuildSecretInfoProps: * @secinfo: pointer to the secret info object @@ -825,8 +809,13 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, goto cleanup; if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { - if ((uri->port = qemuNetworkDriveGetPort(src->hosts->port)) < 0) + if (virStrToLong_i(src->hosts->port, NULL, 10, &uri->port) < 0 || + uri->port < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to parse port number '%s'"), + src->hosts->port); goto cleanup; + } if (VIR_STRDUP(uri->scheme, virStorageNetProtocolTypeToString(src->protocol)) < 0) -- 2.13.2

Negative ports don't make sense so use a unsigned integer. --- src/qemu/qemu_command.c | 3 +-- src/util/viruri.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b994940a2..f7858302b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -809,8 +809,7 @@ qemuBuildNetworkDriveURI(virStorageSourcePtr src, goto cleanup; if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { - if (virStrToLong_i(src->hosts->port, NULL, 10, &uri->port) < 0 || - uri->port < 0) { + if (virStrToLong_uip(src->hosts->port, NULL, 10, &uri->port) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse port number '%s'"), src->hosts->port); diff --git a/src/util/viruri.h b/src/util/viruri.h index 1e53abb0b..7850c38c2 100644 --- a/src/util/viruri.h +++ b/src/util/viruri.h @@ -42,7 +42,7 @@ struct _virURI { char *scheme; /* the URI scheme */ char *server; /* the server part */ char *user; /* the user part */ - int port; /* the port number */ + unsigned int port; /* the port number */ char *path; /* the path string */ char *query; /* the query string */ char *fragment; /* the fragment string */ -- 2.13.2

On Thu, Jul 20, 2017 at 10:00:22 +0200, Peter Krempa wrote:
Peter Krempa (2): qemu: command: Remove qemuNetworkDriveGetPort util: uri: Convert port number to unsigned integer
Self NACK. I'll repost this later with Michal's cleanup patch, since I'll probably change the first patch along with fixing his patch.
participants (1)
-
Peter Krempa