]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virlease: Rework virLeaseReadCustomLeaseFile()
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Dec 2020 15:09:09 +0000 (16:09 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 4 Jan 2021 14:33:30 +0000 (15:33 +0100)
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 <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virlease.c

index aeb605862f8c731a8fe917ceb03506476a9305e2..f01cf5b9bdbfd6aa0c127daeb121e616e541adb0 100644 (file)
@@ -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 {