From 0399293e5b9e5443b82103fa8e2c97deadef9825 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Thu, 3 Mar 2016 09:16:48 -0700 Subject: util: Shorten references into SocketAddress An upcoming patch will alter how simple unions, like SocketAddress, are laid out, which will impact all lines of the form 'addr->u.XXX' (expanding it to the longer 'addr->u.XXX.data'). For better legibility in that patch, and less need for line wrapping, it's better to use a temporary variable to reduce the effect of a layout change to just the variable initializations, rather than every reference within a SocketAddress. Also, take advantage of some C99 initialization where it makes sense (simplifying g_new0() to g_new()). Signed-off-by: Eric Blake Message-Id: <1457021813-10704-7-git-send-email-eblake@redhat.com> Signed-off-by: Markus Armbruster --- block/nbd.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'block/nbd.c') diff --git a/block/nbd.c b/block/nbd.c index db57b49..9f333c9 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -204,18 +204,20 @@ static SocketAddress *nbd_config(BDRVNBDState *s, QDict *options, char **export, saddr = g_new0(SocketAddress, 1); if (qdict_haskey(options, "path")) { + UnixSocketAddress *q_unix; saddr->type = SOCKET_ADDRESS_KIND_UNIX; - saddr->u.q_unix = g_new0(UnixSocketAddress, 1); - saddr->u.q_unix->path = g_strdup(qdict_get_str(options, "path")); + q_unix = saddr->u.q_unix = g_new0(UnixSocketAddress, 1); + q_unix->path = g_strdup(qdict_get_str(options, "path")); qdict_del(options, "path"); } else { + InetSocketAddress *inet; saddr->type = SOCKET_ADDRESS_KIND_INET; - saddr->u.inet = g_new0(InetSocketAddress, 1); - saddr->u.inet->host = g_strdup(qdict_get_str(options, "host")); + inet = saddr->u.inet = g_new0(InetSocketAddress, 1); + inet->host = g_strdup(qdict_get_str(options, "host")); if (!qdict_get_try_str(options, "port")) { - saddr->u.inet->port = g_strdup_printf("%d", NBD_DEFAULT_PORT); + inet->port = g_strdup_printf("%d", NBD_DEFAULT_PORT); } else { - saddr->u.inet->port = g_strdup(qdict_get_str(options, "port")); + inet->port = g_strdup(qdict_get_str(options, "port")); } qdict_del(options, "host"); qdict_del(options, "port"); -- cgit v1.1