From 8e5659ed12d1f181297ed6d4e201bb1d6b6322b6 Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 18 Dec 2020 16:09:09 +0100 Subject: [PATCH] virlease: Rework virLeaseReadCustomLeaseFile() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There are some variables which are used only inside the single loop the function has. Let's declare them inside the loop body to make that obvious. Also, fix indendation. Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé --- src/util/virlease.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/util/virlease.c b/src/util/virlease.c index aeb605862f..f01cf5b9bd 100644 --- a/src/util/virlease.c +++ b/src/util/virlease.c @@ -50,11 +50,7 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new, { g_autofree char *lease_entries = NULL; g_autoptr(virJSONValue) leases_array = NULL; - long long expirytime; int custom_lease_file_len = 0; - virJSONValuePtr lease_tmp = NULL; - const char *ip_tmp = NULL; - const char *server_duid_tmp = NULL; size_t i; /* Read entire contents */ @@ -83,7 +79,11 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new, i = 0; while (i < virJSONValueArraySize(leases_array)) { - if (!(lease_tmp = virJSONValueArrayGet(leases_array, i))) { + virJSONValuePtr lease_tmp = virJSONValueArrayGet(leases_array, i); + long long expirytime; + const char *ip_tmp = NULL; + + if (!lease_tmp) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); return -1; @@ -103,9 +103,10 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new, } if (server_duid && strchr(ip_tmp, ':')) { + const char *server_duid_tmp = NULL; + /* This is an ipv6 lease */ - if ((server_duid_tmp - = virJSONValueObjectGetString(lease_tmp, "server-duid"))) { + if ((server_duid_tmp = virJSONValueObjectGetString(lease_tmp, "server-duid"))) { if (!*server_duid) *server_duid = g_strdup(server_duid_tmp); } else {