From nobody Fri Dec 19 07:49:27 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608304569; cv=none; d=zohomail.com; s=zohoarc; b=lgANkvqFC9icrCv07hGT+p31JmwdLMHewvteZIuFdBDYisVUUwd3WtjNi3RJcdFSX67nTuJJmRtmgLBt+F7ODUNFBRIumJ/FVHAjCiOyXv5BlzJNVlMu4aBelqfyrqah8SJ1OXm8Itzfnasy5zlnVhrA0Q1UnvgBml2yZLsozGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608304569; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=JZzWHQ6QjLxFCw0eU9CJfA4ht2nikYK2TJdfpYdKGwo=; b=J4E6ZdSNs9JTUPRh2Pvav4vT9skvDn5DLQu1vFV39i+a+1YQIcwIlXRIuJV7oceXTM+pIqSLmG5OS+xMRaFLamyKffUE4E50H+42SMXmV8/F8Md7McMiwVv4dp/gkT9shVv46o3y/2tov1hA0eun/VrWRNAwNTYRvgy80h283v4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1608304569672424.4183516451353; Fri, 18 Dec 2020 07:16:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-462-nKJItK-1MtK6fJw1IqhFsw-1; Fri, 18 Dec 2020 10:10:00 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2E220190B2B3; Fri, 18 Dec 2020 15:09:52 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F3C5310023AB; Fri, 18 Dec 2020 15:09:51 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id BBF031809CAA; Fri, 18 Dec 2020 15:09:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BIF9POK014043 for ; Fri, 18 Dec 2020 10:09:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id B6431100AE2D; Fri, 18 Dec 2020 15:09:25 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.214]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2743F100AE2C for ; Fri, 18 Dec 2020 15:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608304326; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JZzWHQ6QjLxFCw0eU9CJfA4ht2nikYK2TJdfpYdKGwo=; b=VkNlmCOpZYq0k3ZUM1Z+HV8d2t0cEOjOVZZBhHcaDb4COxWMsoDXqeNSGkZ/lT6rJmcIMl u/VgqLletkXpdsDXq5gO9jOxw4zd0JED/mbCE8QTEt6jfRIZp+LHRAxCy8ieHe70eNWsrs w0LDzJesZslQSk8Sbjwq+TfO4FqrG5c= X-MC-Unique: nKJItK-1MtK6fJw1IqhFsw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 03/10] virlease: Rework virLeaseReadCustomLeaseFile() Date: Fri, 18 Dec 2020 16:09:09 +0100 Message-Id: <80940e76094b9fb77930d5e40da7a2f87e209a16.1608303776.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D NULL; g_autoptr(virJSONValue) leases_array =3D NULL; - long long expirytime; int custom_lease_file_len =3D 0; - virJSONValuePtr lease_tmp =3D NULL; - const char *ip_tmp =3D NULL; - const char *server_duid_tmp =3D NULL; size_t i; =20 /* Read entire contents */ @@ -83,7 +79,11 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array= _new, =20 i =3D 0; while (i < virJSONValueArraySize(leases_array)) { - if (!(lease_tmp =3D virJSONValueArrayGet(leases_array, i))) { + virJSONValuePtr lease_tmp =3D virJSONValueArrayGet(leases_array, i= ); + long long expirytime; + const char *ip_tmp =3D NULL; + + if (!lease_tmp) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("failed to parse json")); return -1; @@ -103,9 +103,10 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_arr= ay_new, } =20 if (server_duid && strchr(ip_tmp, ':')) { + const char *server_duid_tmp =3D NULL; + /* This is an ipv6 lease */ - if ((server_duid_tmp - =3D virJSONValueObjectGetString(lease_tmp, "server-duid")= )) { + if ((server_duid_tmp =3D virJSONValueObjectGetString(lease_tmp= , "server-duid"))) { if (!*server_duid) *server_duid =3D g_strdup(server_duid_tmp); } else { --=20 2.26.2