From nobody Sat May 18 06:31:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620315084; cv=none; d=zohomail.com; s=zohoarc; b=HI9L9lK4S8yA2zYOdfx+12T3PPX747feMcnI7wu2ou2nd0C9nohO0e8AbKAl3BDoNUHuA0blLDKiFq5DGHh3eldHKC81o8OlstMaky/pRSfD+pc+6CHH/fv+oXI+rjAMMq5Zmsqd+S0x736r6Zw4cDgU/+RDxf6JzuMfjHY+XJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315084; 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=YFmO1M2Zbyl37WaT0ct3JcOGX4m7kdzPpC7CVkOjPE8=; b=kKbWugifgcPJn3YPmaQAROl0mYIH//mhjCEXIO6lMJlJurwoedy95XO0FB/6gGyuaK4/3zzKcaqEUnzY0WwVcD5Bz9j7OCZ0sPhfa/s9q8LGQDGzEKZs5d0d5RXuFx8h0a2ZuKkH3N0vuQLR4ZOrnCKl+9PJjh+kj1u1MXNbrbo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620315084342728.8014956919467; Thu, 6 May 2021 08:31:24 -0700 (PDT) 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-310-Zn_1CPL0PTGqox7SGjCujQ-1; Thu, 06 May 2021 11:31:19 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 587761B2C99D; Thu, 6 May 2021 15:31:14 +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 3078C190E8; Thu, 6 May 2021 15:31:14 +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 EDCF01800FF0; Thu, 6 May 2021 15:31:13 +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 146FVCRb011328 for ; Thu, 6 May 2021 11:31:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2949F1002EF0; Thu, 6 May 2021 15:31:12 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8CB2B105C80B for ; Thu, 6 May 2021 15:31:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315082; 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=YFmO1M2Zbyl37WaT0ct3JcOGX4m7kdzPpC7CVkOjPE8=; b=K1CTBcYTm+NOaao7hBgVn44NY7PDKMWbWvSgyoDIpXM1NwTqZN7DzKihRYU3A4Sz11jdn3 Gr3HeP5UUBDVS25HCbH8ZjebH90AmAnm3U6NY5k48IHHEKcnwJPKeKeOQDKuF1I7NJ7vbN mgKk2qmYxFVQHqwu1GjYKv9qPJwrTmM= X-MC-Unique: Zn_1CPL0PTGqox7SGjCujQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 01/17] util: xml: Extract implementation of xml property -> enum parsing to a common helper Date: Thu, 6 May 2021 17:30:53 +0200 Message-Id: <822ad9b87a415a56625589dd9360467f711f4939.1620314826.git.pkrempa@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.79 on 10.5.11.12 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" virXMLPropTristateBool/virXMLPropTristateSwitch/virXMLPropEnum can be implemented using the same internal code. Extract it into a new function called virXMLPropEnumInternal, which will also simplify adding versions of these functions with a custom default value. This way we'll be able to always initialize @result so that unused value bugs can be prevented. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 108 ++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 66 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 7cc73ab9a0..9929064993 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -557,6 +557,40 @@ virXMLNodeContentString(xmlNodePtr node) return ret; } +static int +virXMLPropEnumInternal(xmlNodePtr node, + const char* name, + int (*strToInt)(const char*), + virXMLPropFlags flags, + unsigned int *result) + +{ + g_autofree char *tmp =3D NULL; + int ret; + + if (!(tmp =3D virXMLPropString(node, name))) { + if (!(flags & VIR_XML_PROP_REQUIRED)) + return 0; + + virReportError(VIR_ERR_XML_ERROR, + _("Missing required attribute '%s' in element '%s'"= ), + name, node->name); + return -1; + } + + ret =3D strToInt(tmp); + if (ret < 0 || + ((flags & VIR_XML_PROP_NONZERO) && (ret =3D=3D 0))) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid value for attribute '%s' in element '%s'= : '%s'."), + name, node->name, NULLSTR(tmp)); + return -1; + } + + *result =3D ret; + return 1; +} + /** * virXMLPropTristateBool: @@ -577,28 +611,10 @@ virXMLPropTristateBool(xmlNodePtr node, virXMLPropFlags flags, virTristateBool *result) { - g_autofree char *tmp =3D NULL; - int val; - - if (!(tmp =3D virXMLPropString(node, name))) { - if (!(flags & VIR_XML_PROP_REQUIRED)) - return 0; - - virReportError(VIR_ERR_XML_ERROR, - _("Missing required attribute '%s' in element '%s'"= ), - name, node->name); - return -1; - } - - if ((val =3D virTristateBoolTypeFromString(tmp)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected 'yes' or 'no'"), - name, node->name, tmp); - return -1; - } + flags |=3D VIR_XML_PROP_NONZERO; - *result =3D val; - return 1; + return virXMLPropEnumInternal(node, name, virTristateBoolTypeFromStrin= g, + flags, result); } @@ -621,28 +637,10 @@ virXMLPropTristateSwitch(xmlNodePtr node, virXMLPropFlags flags, virTristateSwitch *result) { - g_autofree char *tmp =3D NULL; - int val; - - if (!(tmp =3D virXMLPropString(node, name))) { - if (!(flags & VIR_XML_PROP_REQUIRED)) - return 0; - - virReportError(VIR_ERR_XML_ERROR, - _("Missing required attribute '%s' in element '%s'"= ), - name, node->name); - return -1; - } - - if ((val =3D virTristateSwitchTypeFromString(tmp)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected 'on' or 'off'"), - name, node->name, tmp); - return -1; - } + flags |=3D VIR_XML_PROP_NONZERO; - *result =3D val; - return 1; + return virXMLPropEnumInternal(node, name, virTristateSwitchTypeFromStr= ing, + flags, result); } @@ -833,32 +831,10 @@ virXMLPropEnum(xmlNodePtr node, virXMLPropFlags flags, unsigned int *result) { - g_autofree char *tmp =3D NULL; - int ret; - - if (!(tmp =3D virXMLPropString(node, name))) { - if (!(flags & VIR_XML_PROP_REQUIRED)) - return 0; - - virReportError(VIR_ERR_XML_ERROR, - _("Missing required attribute '%s' in element '%s'"= ), - name, node->name); - return -1; - } - - ret =3D strToInt(tmp); - if (ret < 0 || - ((flags & VIR_XML_PROP_NONZERO) && (ret =3D=3D 0))) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid value for attribute '%s' in element '%s'= : '%s'."), - name, node->name, NULLSTR(tmp)); - return -1; - } - - *result =3D ret; - return 1; + return virXMLPropEnumInternal(node, name, strToInt, flags, result); } + /** * virXPathBoolean: * @xpath: the XPath string to evaluate --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315125; cv=none; d=zohomail.com; s=zohoarc; b=S4ZXNKShpRlZHhV0Rk/bUZNtenXY6Qy3lLI4f1lRNtYCBEF5KG5LifXZmllDB6mQCarT2SOxvv9h2rUVPQECddJMm6PToQQWG/JA4458ru7Y3ZF+Xwjd4CPHhOWy1sYpV96O0ErYV/WHCuRKMnUicWfNC5wiSbChM69DDhFqHnw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315125; 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=Uknvjw8SHvSmWiPUdgbRfmVC+/5mQhVuBthzg3N9Qv0=; b=ViIdsknxFE/E3jEm/6znZIFRFhi5DDbSeo22IeKQZwWQuG6UEFGGIZYpu1P/J8g/+Z2+0wlMEBp/Gp05A4QRXQ1BQpt9FXrQT4XVOamUPs/ZpIuYCRKAnw3rIppsBM9EkVzEW3oo5DYj3rYGHb+AhWhvKEU32fzfDDh9QjQkEYg= 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 1620315125480221.1956870966544; Thu, 6 May 2021 08:32:05 -0700 (PDT) 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-24-BuB8QfiOMnet5fbFBI8_sg-1; Thu, 06 May 2021 11:31:23 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50DCA800685; Thu, 6 May 2021 15:31:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1894F62923; Thu, 6 May 2021 15:31:17 +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 C9F1955352; Thu, 6 May 2021 15:31:16 +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 146FVDVd011339 for ; Thu, 6 May 2021 11:31:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 31BAE10016F8; Thu, 6 May 2021 15:31:13 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E89D1002EF0 for ; Thu, 6 May 2021 15:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315123; 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=Uknvjw8SHvSmWiPUdgbRfmVC+/5mQhVuBthzg3N9Qv0=; b=ggdKFrZfl2eBYIOUAM7lN7zztX9eJsTuFjUXw0uCv1TywmFLaZmA4lxIW5saLkpeKzugA6 gqQp69U2x3OF1k5ZUJqE2Vo6BC5X2NtbF7xK4FSKLW8e31WJPtPskr4wn2+VDhNxWfpwK+ fgzn5mHajnQYh+gS5AMs0h5l6jogVGY= X-MC-Unique: BuB8QfiOMnet5fbFBI8_sg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 02/17] virXMLPropULongLong: Always initialize @result Date: Thu, 6 May 2021 17:30:54 +0200 Message-Id: <718f070b5410363a78baaa4ee45b7700b8d77847.1620314826.git.pkrempa@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.79 on 10.5.11.15 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" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 9929064993..707a6a2235 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -762,6 +762,7 @@ virXMLPropUInt(xmlNodePtr node, * @result: The returned value * * Convenience function to return value of an unsigned long long attribute. + * @result is initialized to 0 on error or if the element is not found. * * Returns 1 in case of success in which case @result is set, * or 0 if the attribute is not present, @@ -778,6 +779,8 @@ virXMLPropULongLong(xmlNodePtr node, int ret; unsigned long long val; + *result =3D 0; + if (!(tmp =3D virXMLPropString(node, name))) { if (!(flags & VIR_XML_PROP_REQUIRED)) return 0; --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620315088; cv=none; d=zohomail.com; s=zohoarc; b=AWi/56NOTlZvTPKBw/LM9pZw/Xf0m6Swa2unHVwGdIv32GliuQaAuxXf615lGQQzPx8bj0c8+4UHynQSwOm1BCQU//SdelnqUthfO4A83IVnSqk9S384fi9To22ZGUXHQw0UPFf2ZAKcP2s/ypuaRXulxPBAVwnUXTR1uLspiPk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315088; 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=jp2PUzu0TD8PaenIKKZplSZEH6zLBAl0OAI6c6PDP7E=; b=SPBdA19JBdVWblC9rB2bZsSTC0VtMPl9TPel7Z1MPQuta4W+8upCjd2bBP5yNco21SBZFRbyuB42U/aTWkm8HSY3qLfsWQlt4FkDUS1Cgxf7+1vtGVS2glIQUlwO6F5qyqiZdX1HB7NsQoK/GiTGX6JyM0HKnl0paeg7JDQzhJY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620315088905618.3441420619013; Thu, 6 May 2021 08:31:28 -0700 (PDT) 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-26--dteetfzP7yJBcdbeW5gsw-1; Thu, 06 May 2021 11:31:21 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A1983107ACFE; Thu, 6 May 2021 15:31:16 +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 8478760862; Thu, 6 May 2021 15:31:16 +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 4B3361800FF0; Thu, 6 May 2021 15:31:16 +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 146FVEj6011349 for ; Thu, 6 May 2021 11:31:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C6E31079149; Thu, 6 May 2021 15:31:14 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 932961079148 for ; Thu, 6 May 2021 15:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315085; 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=jp2PUzu0TD8PaenIKKZplSZEH6zLBAl0OAI6c6PDP7E=; b=MWO6McW2H9XTZ/ICRjTRmQwjekY+0TH1lJ+ODYyCTrqAjENQSaLffFrJTbOLN93BDA+9oH GVcf3tuSX4yvxDs7xvrQ5o3PhLTjG63az/Slk4R/c45YAiZn+ek20BwXhyS0yuJE2pikCk ZlguqPyD5g2HNOznh0wM/3KZnz/pKf4= X-MC-Unique: -dteetfzP7yJBcdbeW5gsw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/17] virDomainVcpuParse: Assign default vcpus count based on return value of virXMLPropUInt Date: Thu, 6 May 2021 17:30:55 +0200 Message-Id: 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.79 on 10.5.11.13 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" Assign the vcpu count when virXMLPropUInt returns '0' meaning that the cpu count was not present in the XML. This will allow to always initialize the value of @result in virXMLPropUInt to prevent use of uninitialized values. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f536630d72..a2dd7d649f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18030,6 +18030,7 @@ virDomainVcpuParse(virDomainDef *def, unsigned int vcpus; g_autofree char *tmp =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; + int rc; vcpus =3D maxvcpus =3D 1; @@ -18044,10 +18045,11 @@ virDomainVcpuParse(virDomainDef *def, } VIR_FREE(tmp); - vcpus =3D maxvcpus; - - if (virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_NONE, &vc= pus) < 0) + if ((rc =3D virXMLPropUInt(vcpuNode, "current", 10, VIR_XML_PROP_N= ONE, &vcpus)) < 0) { return -1; + } else if (rc =3D=3D 0) { + vcpus =3D maxvcpus; + } def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; if (virXMLPropEnum(vcpuNode, "placement", --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315096; cv=none; d=zohomail.com; s=zohoarc; b=G92JJ6KgtZGQbniwTQa6+oydFUGUSiXhmu0AI5xuY5z0KyK2mRYNC+U+co+O8VmvxSdaTdxK75bnwVKTr1ZgOGKv5NjC971P+M8VN3/+SQ0R6CIE6TEe+SyW+u0SEHrfeiwrqnxZ0EcJX8qg7J+ahHleCopROOjITxGEKoy5eLA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315096; 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=ceW4duf68OzcA1Y95VqPm7f/AhBJCBqlsrnfnFPUMb8=; b=G4Q46kZPaHmrDPAhdPL/wDkjRfHccebWjz4DvpuN2c7syGWsg0rRePkOkJ6aCL7PX/PbG77eQoD/wqvDdbOMivvhGcgFTJSiwX3gmVj+akayW8gh45HNgxuFtCoGGN4ZVzStm4bmPVIJUTio6am3fV9faPskAtdRuekmgof6fhI= 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 1620315096955590.2935493654677; Thu, 6 May 2021 08:31:36 -0700 (PDT) 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-349-j800aHJkOO2tXPWgh4uLtw-1; Thu, 06 May 2021 11:31:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 810046D26E; Thu, 6 May 2021 15:31:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F60F2B6CA; Thu, 6 May 2021 15:31:20 +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 E153455357; Thu, 6 May 2021 15:31:19 +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 146FVFpg011356 for ; Thu, 6 May 2021 11:31:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C9A11045E87; Thu, 6 May 2021 15:31:15 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id A18331079151 for ; Thu, 6 May 2021 15:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315094; 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=ceW4duf68OzcA1Y95VqPm7f/AhBJCBqlsrnfnFPUMb8=; b=GgL34hMYgJOO/DvzhGWdOuzTdytB/uc0gHm0c+fUyNMxbPibcgPezhHFWPxO4mr+JNILBW o5736urR3fDLsMGhGsXYfSvS1/NcccGMPvqmY1R/UTbj1qHJ6vwck17pGiNzwjnv9aqR0O wcQQPUR2NXiS23szRBi+F4HjMrhbs2Q= X-MC-Unique: j800aHJkOO2tXPWgh4uLtw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 04/17] virDomainDiskDefDriverParseXML: Fix usage of virXMLPropUInt Date: Thu, 6 May 2021 17:30:56 +0200 Message-Id: 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.23 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" VIR_XML_PROP_NONE has value of 0 so it's pointless to include it in an binary-or expression. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a2dd7d649f..baf5d31606 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8923,9 +8923,7 @@ virDomainDiskDefDriverParseXML(virDomainDiskDef *def, VIR_XML_PROP_NONZERO, &def->discard) < 0) return -1; - if (virXMLPropUInt(cur, "iothread", 10, - VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO, - &def->iothread) < 0) + if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONZERO, &def->io= thread) < 0) return -1; if ((tmp =3D virXMLPropString(cur, "type"))) { --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315137; cv=none; d=zohomail.com; s=zohoarc; b=Sbn9BL4d0bBfeqzy36bI9k6k1hjl083EjG0PDkWfS8tHrN9Gzcs28GoXTvWGA6HJZRTdI4MnThiA7yCUz0fvv+68hHyCIjxSfrIziKKLKEE2Rb9kL52F1QJ8D6/Atw9KnOiCWUktXQDZjQibE54psYS6JUs3u3lkSQ6JPi0TikM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315137; 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=2nBXxX/RflK7WtSF/VGVD0Rgyu9iSJiZyNlQEzUxdnw=; b=NzmcrYzrBMFQPaHxwtMRId56QLPl0wN/WEI9QcIiXUjmu3QP3yK7VQ0wHeCEoXveYOLi016qYnCYVLO5utllroIrJgUgWfvFSzFvSfogVL8e3174MO2Nb8ioAbL06CLn3i7OS3QC2JtFB29NO6p4ZPVvb2Sq71ahSVnNboUCofM= 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 1620315137515894.2088615175991; Thu, 6 May 2021 08:32:17 -0700 (PDT) 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-258-UwWKyU4rNNecR_WiPsK_cw-1; Thu, 06 May 2021 11:31:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5528D100A68C; Thu, 6 May 2021 15:31:18 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D8B019D61; Thu, 6 May 2021 15:31:18 +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 E672355352; Thu, 6 May 2021 15:31:17 +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 146FVGKC011372 for ; Thu, 6 May 2021 11:31:16 -0400 Received: by smtp.corp.redhat.com (Postfix) id 539F110027A5; Thu, 6 May 2021 15:31:16 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id A8E1310016F8 for ; Thu, 6 May 2021 15:31:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315135; 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=2nBXxX/RflK7WtSF/VGVD0Rgyu9iSJiZyNlQEzUxdnw=; b=hb5Z97OwXBVt69sA288xmMjBFZ81c6NCWQZEfQS025LQHY9OAqpH/Z7LhAvWJrLy9olGnB 4PE5VZv0mbQwOw9xKgu+XhdkR/+O1X2dpUpwBEDrluKtFKN6XJusXx8Iw5hKX5o5/T9SlK 3ObZajZak7ieiaGZCPXQaVbCsFO5gyc= X-MC-Unique: UwWKyU4rNNecR_WiPsK_cw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 05/17] virXMLPropUInt: Always initialize @result Date: Thu, 6 May 2021 17:30:57 +0200 Message-Id: <6d688354757371f227d1bec05551d53401db0ffd.1620314826.git.pkrempa@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.23 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" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 707a6a2235..a03cbf7265 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -706,6 +706,7 @@ virXMLPropInt(xmlNodePtr node, * @result: The returned value * * Convenience function to return value of an unsigned integer attribute. + * @result is initialized to 0 on error or if the element is not found. * * Returns 1 in case of success in which case @result is set, * or 0 if the attribute is not present, @@ -722,6 +723,8 @@ virXMLPropUInt(xmlNodePtr node, int ret; unsigned int val; + *result =3D 0; + if (!(tmp =3D virXMLPropString(node, name))) { if (!(flags & VIR_XML_PROP_REQUIRED)) return 0; --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620315098; cv=none; d=zohomail.com; s=zohoarc; b=Jgyrn0qUvQXqzscfxMIZyEk5CK3gpcLjHD/sfgy84WojcaTfK9u4cUEUdICkqhs7JV135oPPP4tVwBSOqC/K4xRfn1+3cU6DdQsui0ibHrkkUbAGat/ucnbhBTxjaAlqe4sajl8GLIMPT0dMh2dgt8ZW+R4J2lbCF6aY1jbpyFE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315098; 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=vOq+trm35GlLN4StPMMbv10Sise6X7z5D+jRQGmSIjs=; b=Xj2QQLmKfWUTPw6ITAWIZ534OCcEEYAbHsBNBszLrWRwKqYUAnFbQIykz4/lNdbwBLnAhH0xfAxPsyxjlJHTtXLNca2yRzl8HxQcU9HpMgRw8ruWGHdkV6O0rVUF6OMa9r+F1C2w0OdT1KwKsb3SygsVXkwB5FzVa8JFumAJVd0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620315098257813.7394915723903; Thu, 6 May 2021 08:31:38 -0700 (PDT) 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-542-D7F5qjTBMUGL5N9UCOELRg-1; Thu, 06 May 2021 11:31:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3CF091020C51; Thu, 6 May 2021 15:31:23 +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 14D4916909; Thu, 6 May 2021 15:31:23 +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 D19221800B8A; Thu, 6 May 2021 15:31:22 +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 146FVHYn011380 for ; Thu, 6 May 2021 11:31:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5C8131045E87; Thu, 6 May 2021 15:31:17 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0E9E1002D71 for ; Thu, 6 May 2021 15:31:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315095; 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=vOq+trm35GlLN4StPMMbv10Sise6X7z5D+jRQGmSIjs=; b=fARGjMIf+VVLL9c8W880gA3k7UFVLx4RAc5cQEktzkDOe+VjuJXDSGiHsry6vKNJykO7Vc +mkFcQzmGjLyka3FHluyZweJ8mqrQtboO3lV85E0/jMDXj7FuCZMiRonMen/WQuLlTBwwS 7KuJJIKagx9dKrAtP5I87gDBKgE9tLE= X-MC-Unique: D7F5qjTBMUGL5N9UCOELRg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 06/17] conf: Define autoptr func for virDomainIOThreadIDDef Date: Thu, 6 May 2021 17:30:58 +0200 Message-Id: <5d69af8f57d10efbe9d47c8cc1965aa45509d176.1620314826.git.pkrempa@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.79 on 10.5.11.12 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" Register virDomainIOThreadIDDefFree to do the cleanup. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 64465dd8d6..2d5462bb55 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2531,6 +2531,7 @@ struct _virDomainIOThreadIDDef { }; void virDomainIOThreadIDDefFree(virDomainIOThreadIDDef *def); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virDomainIOThreadIDDef, virDomainIOThreadIDD= efFree); struct _virDomainCputune { --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620315095; cv=none; d=zohomail.com; s=zohoarc; b=YxzrcrvVlP+eW9IY+FNV8UZx0TjidzHL7v8MP+P3u+iOUrQwrq2+3IqJXppu7ZJfA+REtPtdNkJrFUGv3vzKLeYLWR6sZrFpn2iFM4on5bj0+zHD2FTMt/lBkYnCs9byBJpyyBoGxO1OdK2wpopTz0gxtBDyl2pT96uKZ/GfM7A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315095; 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=XUoiWPK8K50XkpaZdLh+T1YeE9n8E8+xsjkR/7U2WRQ=; b=eEZKJbeM6qFc8T0GNZ/O9p44Mh1XRGYhdDf6hluS11eHPxTh2HwnK8p08sm7MqgBxZjcRp+7yp7QnnRTWVnnEG3DqzlEeoWLZXsH+EBY4/g4PvuS/cBQLHpNQYBsMtMb0WVPEh9HZak4YkzGVBWFJD4+YDRrcipPvK/fH6ad9P8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620315095589376.11960817460044; Thu, 6 May 2021 08:31:35 -0700 (PDT) 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-FFEYtTuSOzuBdsGrKNAZXA-1; Thu, 06 May 2021 11:31:31 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7BDDC18397BD; Thu, 6 May 2021 15:31:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A9DC5D6AC; Thu, 6 May 2021 15:31:21 +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 178D255357; Thu, 6 May 2021 15:31:21 +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 146FVIkM011388 for ; Thu, 6 May 2021 11:31:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 71A291045E8C; Thu, 6 May 2021 15:31:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id C5ECA1045E87 for ; Thu, 6 May 2021 15:31:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315093; 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=XUoiWPK8K50XkpaZdLh+T1YeE9n8E8+xsjkR/7U2WRQ=; b=S/4Yza3znC00E5pKDxnuaPu5K/q487YGTtyrwQZC0r1QwxIx3ob9cWiE8SZqybR4RRaE4z kPvbEuRzafIanragKcxOUv8oIIRygB7tWn1KXeBSyiWliD1u/8NuWbPQT9pWReUeLx+DGe 311MMFrBn/U1gHGygt+kx8UedVEUKr8= X-MC-Unique: FFEYtTuSOzuBdsGrKNAZXA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/17] virDomainIOThreadIDDefParseXML: Refactor cleanup Date: Thu, 6 May 2021 17:30:59 +0200 Message-Id: <579d93aa2a6f4482883e15eb00e86c1c2d7e9410.1620314826.git.pkrempa@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.79 on 10.5.11.15 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" Automatically free 'iothrid' and remove all the cleanup cruft. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index baf5d31606..78775bb2b3 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17010,21 +17010,14 @@ virDomainIdmapDefParseXML(xmlXPathContextPtr ctxt, static virDomainIOThreadIDDef * virDomainIOThreadIDDefParseXML(xmlNodePtr node) { - virDomainIOThreadIDDef *iothrid; - - iothrid =3D g_new0(virDomainIOThreadIDDef, 1); + g_autoptr(virDomainIOThreadIDDef) iothrid =3D g_new0(virDomainIOThread= IDDef, 1); if (virXMLPropUInt(node, "id", 10, VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, &iothrid->iothread_id) < 0) - goto error; - - return iothrid; + return NULL; - error: - virDomainIOThreadIDDefFree(iothrid); - iothrid =3D NULL; - return iothrid; + return g_steal_pointer(&iothrid); } --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315100; cv=none; d=zohomail.com; s=zohoarc; b=XJJzwgIjAe15Nti3MiLH/KkoeiDcr9G+ST1KN+H11ndUWN2Go8TyZGDnOcUQu82hu4KcUeer2JrDj5KxITsUT8QhdNnIMB4z1Jh8GA0WafU+q9STSMdziC9/mbwaUbDe2YyoBjrSWWQGVoH9n8wufA3UyzyOVeEvzUxaj+Grm6k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315100; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=c4E+mMKLT3/j0lDZ1tzfIKQ0ChVjpdBOI50tlWGt2Yznrz1p+wghPWhMtB3CLaK19VqbASqByxxxhiKSQcnI6JJEmMfn1rzYqeogSar3hzQ0XxTfDeSObjucuQQPSxAmzjFZB8hkuzcXBys4aGiTUPQzeUHE0Aij9D9OugOCTek= 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 1620315100229992.914061990832; Thu, 6 May 2021 08:31:40 -0700 (PDT) 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-421-Y9yl6hIaM5Cb5OMiQnsY9Q-1; Thu, 06 May 2021 11:31:30 -0400 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 762298049D8; Thu, 6 May 2021 15:31:21 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 47C7C1059582; Thu, 6 May 2021 15:31:21 +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 069B755358; Thu, 6 May 2021 15:31:21 +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 146FVJDM011403 for ; Thu, 6 May 2021 11:31:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9350E105C7E1; Thu, 6 May 2021 15:31:19 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id DBC1C1079148 for ; Thu, 6 May 2021 15:31:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315093; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=bewOkST80LXed3AEJ6UTmpeB5WTfYZr3YT88qYqmQ73ZT2OT6IF7YXLObaSKxq9tr3zetV 4FVxN0p+p86YNdqMAJZ41ZF0SIacqG3jkMo8mnYCnKevGgGc/AmiQrjZD3IJGA+CS+0Pbx 7cHToKWL7RIMB0jR7LcG0uuy1ez1Om4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315099; 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=YNOPkVnnciN/e6wHBRmW7buoWEuEAdqOKqDj+yXy6Q8=; b=SqyRas9MuDbxR08hUMwMrQcrm/WQzUMnjcis93zfbAv7N2UiZ0NmCMUOyPLxMCdHSC9byM S6jd4OgXyXTsLlwVaTe52CpW2D/lh8w/2gojpYrrBR4BGqfhjhzasacT5/YewSRwnlzdIk aqfequ/Bn7yix7vYboTaFypGiNrXTM4= X-MC-Unique: Y9yl6hIaM5Cb5OMiQnsY9Q-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/17] virXMLPropInt: Always initialize '@result' Date: Thu, 6 May 2021 17:31:00 +0200 Message-Id: <22113bbe4b50f2446e2b488c4d58f75abf7b6bbe.1620314826.git.pkrempa@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) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. This is done by adding a @defaultResult argument to virXMLPropInt since many places have a non-0 default. In certain cases such as in virDomainControllerDefParseXML we pass the value from the original value, which will still trigger compiler checks if unused while preserving the existing functionality of keeping the previous value. This commit fixes 3 uses of uninitialized value parsed by this function: in virDomainDiskSourceNetworkParse introduced by 38dc25989c5 in virDomainChrSourceDefParseTCP introduced by fa48004af5b in virDomainGraphicsListenDefParseXML introduced by 0b20fd3754c Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 57 +++++++++++++++++++++--------------------- src/util/virxml.c | 6 ++++- src/util/virxml.h | 3 ++- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 78775bb2b3..2bc2e55ee4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8221,7 +8221,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, if (flags & VIR_DOMAIN_DEF_PARSE_STATUS) { int value; if (virXMLPropInt(node, "tlsFromConfig", 10, VIR_XML_PROP_NONE, - &value) < 0) + &value, 0) < 0) return -1; src->tlsFromConfig =3D !!value; } @@ -9414,7 +9414,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, g_autofree xmlNodePtr *modelNodes =3D NULL; int nmodelNodes =3D 0; int numaNode =3D -1; - int ports =3D -1; + int ports; VIR_XPATH_NODE_AUTORESTORE(ctxt) int rc; g_autofree char *idx =3D NULL; @@ -9494,19 +9494,23 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, if (ntargetNodes =3D=3D 1) { if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { if (virXMLPropInt(targetNodes[0], "chassisNr", 0, VIR_XML_PROP_NON= E, - &def->opts.pciopts.chassisNr) < 0) + &def->opts.pciopts.chassisNr, + def->opts.pciopts.chassisNr) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "chassis", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.chassis) < 0) + &def->opts.pciopts.chassis, + def->opts.pciopts.chassis) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "port", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.port) < 0) + &def->opts.pciopts.port, + def->opts.pciopts.port) < 0) return NULL; if (virXMLPropInt(targetNodes[0], "busNr", 0, VIR_XML_PROP_NONE, - &def->opts.pciopts.busNr) < 0) + &def->opts.pciopts.busNr, + def->opts.pciopts.busNr) < 0) return NULL; if (virXMLPropTristateSwitch(targetNodes[0], "hotplug", @@ -9515,7 +9519,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, return NULL; if ((rc =3D virXMLPropInt(targetNodes[0], "index", 0, VIR_XML_PROP= _NONE, - &def->opts.pciopts.targetIndex)) < 0) + &def->opts.pciopts.targetIndex, + def->opts.pciopts.targetIndex)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D=3D -1) @@ -9548,7 +9553,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, return NULL; } - if ((rc =3D virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports= )) < 0) + if ((rc =3D virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports= , -1)) < 0) return NULL; if ((rc =3D=3D 1) && ports < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -9559,7 +9564,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { if ((rc =3D virXMLPropInt(node, "vectors", 10, VIR_XML_PROP_NONE, - &def->opts.vioserial.vectors)) < 0) + &def->opts.vioserial.vectors, + def->opts.vioserial.vectors)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.vioserial.vectors < 0) { @@ -9630,7 +9636,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, break; case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: { if ((rc =3D virXMLPropInt(node, "maxGrantFrames", 10, VIR_XML_PROP= _NONE, - &def->opts.xenbusopts.maxGrantFrames)) < 0) + &def->opts.xenbusopts.maxGrantFrames, + def->opts.xenbusopts.maxGrantFrames)) < 0) return NULL; if ((rc =3D=3D 1) && def->opts.xenbusopts.maxGrantFrames < 0) { @@ -9641,7 +9648,8 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, } if ((rc =3D virXMLPropInt(node, "maxEventChannels", 10, VIR_XML_PR= OP_NONE, - &def->opts.xenbusopts.maxEventChannels)) <= 0) + &def->opts.xenbusopts.maxEventChannels, + def->opts.xenbusopts.maxEventChannels)) < = 0) return NULL; if ((rc =3D=3D 1) && def->opts.xenbusopts.maxEventChannels < 0) { @@ -11181,7 +11189,7 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDef= *def, int tmpVal; if (virXMLPropInt(source, "tlsFromConfig", 10, VIR_XML_PROP_NONE, - &tmpVal) < 0) + &tmpVal, 0) < 0) return -1; def->data.tcp.tlsFromConfig =3D !!tmpVal; } @@ -12376,7 +12384,7 @@ virDomainGraphicsListenDefParseXML(virDomainGraphic= sListenDef *def, if (flags & VIR_DOMAIN_DEF_PARSE_STATUS) { int tmp; - if (virXMLPropInt(node, "fromConfig", 10, VIR_XML_PROP_NONE, &tmp)= < 0) + if (virXMLPropInt(node, "fromConfig", 10, VIR_XML_PROP_NONE, &tmp,= 0) < 0) return -1; def->fromConfig =3D tmp !=3D 0; } @@ -12519,7 +12527,7 @@ virDomainGraphicsDefParseXMLVNC(virDomainGraphicsDe= f *def, } if (virXMLPropInt(node, "websocket", 10, VIR_XML_PROP_NONE, - &def->data.vnc.websocket) < 0) + &def->data.vnc.websocket, 0) < 0) return -1; if (websocketGenerated) @@ -12663,14 +12671,12 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDef *def, if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; - def->data.spice.port =3D 0; if (virXMLPropInt(node, "port", 10, VIR_XML_PROP_NONE, - &def->data.spice.port) < 0) + &def->data.spice.port, 0) < 0) return -1; - def->data.spice.tlsPort =3D 0; if (virXMLPropInt(node, "tlsPort", 10, VIR_XML_PROP_NONE, - &def->data.spice.tlsPort) < 0) + &def->data.spice.tlsPort, 0) < 0) return -1; if (virXMLPropTristateBool(node, "autoport", VIR_XML_PROP_NONE, @@ -13527,7 +13533,6 @@ virDomainMemballoonDefParseXML(virDomainXMLOption *= xmlopt, virDomainMemballoonDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr stats; - unsigned int period =3D 0; ctxt->node =3D node; @@ -13546,10 +13551,9 @@ virDomainMemballoonDefParseXML(virDomainXMLOption = *xmlopt, &def->free_page_reporting) < 0) goto error; - def->period =3D period; if ((stats =3D virXPathNode("./stats", ctxt))) { if (virXMLPropInt(stats, "period", 0, VIR_XML_PROP_NONE, - &def->period) < 0) + &def->period, 0) < 0) goto error; if (def->period < 0) @@ -14509,8 +14513,7 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr no= de) def =3D g_new0(virDomainRedirFilterUSBDevDef, 1); - def->usbClass =3D -1; - if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass)= < 0) + if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass,= -1) < 0) return NULL; if (def->usbClass !=3D -1 && def->usbClass &~ 0xFF) { @@ -14519,12 +14522,10 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr = node) return NULL; } - def->vendor =3D -1; - if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor) = < 0) + if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor, = -1) < 0) return NULL; - def->product =3D -1; - if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product= ) < 0) + if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product= , -1) < 0) return NULL; version =3D virXMLPropString(node, "version"); @@ -17868,7 +17869,7 @@ virDomainSchedulerParseCommonAttrs(xmlNodePtr node, if (*policy =3D=3D VIR_PROC_POLICY_FIFO || *policy =3D=3D VIR_PROC_POL= ICY_RR) { if (virXMLPropInt(node, "priority", 10, VIR_XML_PROP_REQUIRED, - priority) < 0) + priority, 0) < 0) return -1; } diff --git a/src/util/virxml.c b/src/util/virxml.c index a03cbf7265..449453121f 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -651,6 +651,7 @@ virXMLPropTristateSwitch(xmlNodePtr node, * @base: Number base, see strtol * @flags: Bitwise or of virXMLPropFlags * @result: The returned value + * @defaultResult: default value of @result in case the property is not fo= und * * Convenience function to return value of an integer attribute. * @@ -663,11 +664,14 @@ virXMLPropInt(xmlNodePtr node, const char *name, int base, virXMLPropFlags flags, - int *result) + int *result, + int defaultResult) { g_autofree char *tmp =3D NULL; int val; + *result =3D defaultResult; + if (!(tmp =3D virXMLPropString(node, name))) { if (!(flags & VIR_XML_PROP_REQUIRED)) return 0; diff --git a/src/util/virxml.h b/src/util/virxml.h index eb92fbf94e..939d2482cb 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -123,7 +123,8 @@ virXMLPropInt(xmlNodePtr node, const char *name, int base, virXMLPropFlags flags, - int *result) + int *result, + int defaultResult) ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4); int --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315100; cv=none; d=zohomail.com; s=zohoarc; b=nowovYT2jYSROSsGQW59C33SHnEcZb8fP1KUz+M+ukgEEs5zsTSadFpUJ3NgiuyUA81iJ9XN30bCfX+WX6WvuE/JMg3fe1NtoQR8NezC27z+8J7f5LPFZQ3hxVVxsWCf9h4KxUyX5PdoSZfm+2ezTv+qsYgPLPWCaLThDHZrFRs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315100; 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=oVLFHgzDLtEd/Wh0/bT1WT4J5RRvXflFZ5JEFrWC7y4=; b=Y7yVQZyHsE5Jqf9m+gkILxMJWydUrRiyzeKEHoBGZHDnwRbPVWISla3FffgRLhF28KEmZ1iQojr+lcSx972lGj/lOB7+4vTFsY59hTwQuvn3LwKVUjToWFivgQS8ib6s+3JSZPdy7EO4iHnZdUMQAo4zliFNpLjhcKbEEeiMKxA= 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 162031510096538.5665055308458; Thu, 6 May 2021 08:31:40 -0700 (PDT) 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-429-Q-S69n_dMEivgSpbKrO2WA-1; Thu, 06 May 2021 11:31:35 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9FB593A807; Thu, 6 May 2021 15:31:25 +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 CC5D11349A; Thu, 6 May 2021 15:31:25 +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 9A4EE180B651; Thu, 6 May 2021 15:31:25 +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 146FVKbE011409 for ; Thu, 6 May 2021 11:31:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 959D11059582; Thu, 6 May 2021 15:31:20 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDC261002EF0 for ; Thu, 6 May 2021 15:31:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315098; 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=oVLFHgzDLtEd/Wh0/bT1WT4J5RRvXflFZ5JEFrWC7y4=; b=CWAJmtAlFWb4wRTSfoIKxoFO6njMCadUUbL3F2fitvMl1GmMkFahYg+y7OGKt76nWnVGcB KMmkM34BPgFH/9DRwbQ/q9kn1yBbnjrl57PFwTcSf41ipWCp5HqhLtwn1mT8Vvc2Jxepsr 52uhDpNKmnjWRnuo3FKdOPVX7Fx//aM= X-MC-Unique: Q-S69n_dMEivgSpbKrO2WA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 09/17] virDomainBackupDiskDefParseXML: Fill default backup state after parsing it Date: Thu, 6 May 2021 17:31:01 +0200 Message-Id: <83ae551b93d289c05ae48805f6304180741a71c9.1620314826.git.pkrempa@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.79 on 10.5.11.11 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" Set the backup mode to VIR_TRISTATE_BOOL_YES after virXMLPropTristateBool left it set to VIR_TRISTATE_BOOL_ABSENT. This will allow fixing virXMLPropTristateBool to always initialize @result. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/backup_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c index 7f176b783f..ac92bd4f26 100644 --- a/src/conf/backup_conf.c +++ b/src/conf/backup_conf.c @@ -121,12 +121,13 @@ virDomainBackupDiskDefParseXML(xmlNodePtr node, return -1; } - def->backup =3D VIR_TRISTATE_BOOL_YES; - if (virXMLPropTristateBool(node, "backup", VIR_XML_PROP_NONE, &def->backup) < 0) return -1; + if (def->backup =3D=3D VIR_TRISTATE_BOOL_ABSENT) + def->backup =3D VIR_TRISTATE_BOOL_YES; + /* don't parse anything else if backup is disabled */ if (def->backup =3D=3D VIR_TRISTATE_BOOL_NO) return 0; --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315215; cv=none; d=zohomail.com; s=zohoarc; b=eywnJGsIbDy7ZRIHgX5F/kDezAuNcFBt4sos/LOV9dgS+OQdN4UmfLe26OKjPBIqOZNBuecYfGaC/md5AOtUWIaN9u69Z8eHMZo4zBKgTDmnHOZulJucYVIhqcBYOk/vWJAB+E9+vc1+fHMJZ2NuK39ebONAbPPeF1ARwI6jEJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315215; 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=VQtkW6w6MBukConMyE92YJV5zC6cWNPGcJBJR8XiKJE=; b=d+nHHhkCcSWBjGcM1Hvky87wTnsm5n27V0BueW6DOWAG3jGWCfk5FvRb5EI61ZMQ4GVLcrIXXCNOxdpIqWDJaM24dAw2/yuDO0j/0kB0nninb4/yJ4ObvtDa41nGc56RxcIFhEX7RLDbVuxAOoG34W+o0qEgtMv/ApmmMHXgj1Y= 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 1620315215372162.07607663035378; Thu, 6 May 2021 08:33:35 -0700 (PDT) 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-13-glUX0jBXP5OW6hghNL4QmA-1; Thu, 06 May 2021 11:31:34 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E04D80D6A8; Thu, 6 May 2021 15:31:24 +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 3BDD11349A; Thu, 6 May 2021 15:31:24 +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 EAACB180B651; Thu, 6 May 2021 15:31:23 +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 146FVLBX011427 for ; Thu, 6 May 2021 11:31:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id A34641059582; Thu, 6 May 2021 15:31:21 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E7E51059595 for ; Thu, 6 May 2021 15:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315213; 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=VQtkW6w6MBukConMyE92YJV5zC6cWNPGcJBJR8XiKJE=; b=T9Z9CgoKmyy/N6khWcoKhJLZ824URCBQv7yK7bZZm38mFprYy/Qb6OMhxmwT51G5zXRbce 7rYjffEwgoBqwQqYSd6RvUAy1u+nQlU30W6pkTLxBvIq7AE5TyIwrmYhP9XU3MH+4pr0He EfZuStME10XLDtGXfx7Mg2sgxBMcjQg= X-MC-Unique: glUX0jBXP5OW6hghNL4QmA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/17] virXMLPropTristateBool: Always initialize '@result' Date: Thu, 6 May 2021 17:31:02 +0200 Message-Id: <31e220311709825f57a57e277d377c64d9fb4237.1620314826.git.pkrempa@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.79 on 10.5.11.11 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" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/util/virxml.c b/src/util/virxml.c index 449453121f..d9bc5199b3 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -600,6 +600,8 @@ virXMLPropEnumInternal(xmlNodePtr node, * @result: The returned value * * Convenience function to return value of a yes / no attribute. + * In case when the property is missing @result is initialized to + * VIR_TRISTATE_BOOL_ABSENT. * * Returns 1 in case of success in which case @result is set, * or 0 if the attribute is not present, @@ -613,6 +615,8 @@ virXMLPropTristateBool(xmlNodePtr node, { flags |=3D VIR_XML_PROP_NONZERO; + *result =3D VIR_TRISTATE_BOOL_ABSENT; + return virXMLPropEnumInternal(node, name, virTristateBoolTypeFromStrin= g, flags, result); } --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1620315100; cv=none; d=zohomail.com; s=zohoarc; b=NzO0p3PI+OFJ3qOAQY8K6GtjaAKSvP6dZYdCaVBBMjH9bLeUhF0V8be1HB9H66scgmHSyN+nLgJPgWEdZGECVikAEckmfiBJNY4IezCI9+oI7Zp43cIPCyVL3rLnIuUw5cwpC8ItuAkV7C5EAOU60u6KEnA401BlWbMAo+G94Ok= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315100; 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=DrYDA3shNWQFNxhF+xkOepIJwbJXzfa3ZcM5RJR12Dg=; b=URqWp89tHpwSWQVX2qmZzqxzWYWCSjYxvmq7J1a0MMwKOkXBmtUQ/ivi0NEuopdaVbUMm6jONuN3NjgNSsfSIQHiIwymb9YJwc2VuOEwFWSJc4vwRYhjXXkw+FBEUl81ktjvtXbMb5Fx+73jB31PsNeN+IcWTYBCTer66NDfvk4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1620315100697631.5843006312524; Thu, 6 May 2021 08:31:40 -0700 (PDT) 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-474-aF8BloXbPneCiHFj83Dv6A-1; Thu, 06 May 2021 11:31:35 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E050A6D505; Thu, 6 May 2021 15:31:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6D025D72F; Thu, 6 May 2021 15:31:26 +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 7BA705535A; Thu, 6 May 2021 15:31:26 +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 146FVMxl011434 for ; Thu, 6 May 2021 11:31:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id B4EBE105959E; Thu, 6 May 2021 15:31:22 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 19A531059582 for ; Thu, 6 May 2021 15:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315098; 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=DrYDA3shNWQFNxhF+xkOepIJwbJXzfa3ZcM5RJR12Dg=; b=aJ4r/be6HuhhrHqeJmj8PqiqjfaKsUCu4PwBljBftYP+6Dd3ikl0OkuUjCu65ROs3Ug6y2 lO4Ag2/EUdLM+jSdlU38d8Ozm3w0a0swvml8CCIteTvjR/Sp6SK1VseUxulXQvF2fXmUFL oO94PZxSQ2X6Vt5sh6GLXk2ZkoW5Ym8= X-MC-Unique: aF8BloXbPneCiHFj83Dv6A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/17] conf: domain: Don't initialize virTristateBool local variables used for virXMLPropTristateBool Date: Thu, 6 May 2021 17:31:03 +0200 Message-Id: <393cca917dac4d138ccc77a726c863467ff7b1f1.1620314826.git.pkrempa@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.79 on 10.5.11.15 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" virXMLPropTristateBool already initializes the value to VIR_TRISTATE_BOOL_ABSENT so we no longer need to do that for certain local variables. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2bc2e55ee4..ea99a4c40a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12569,7 +12569,7 @@ virDomainGraphicsDefParseXMLSDL(virDomainGraphicsDe= f *def, { VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr glNode; - virTristateBool fullscreen =3D VIR_TRISTATE_BOOL_NO; + virTristateBool fullscreen; ctxt->node =3D node; @@ -12640,7 +12640,7 @@ static int virDomainGraphicsDefParseXMLDesktop(virDomainGraphicsDef *def, xmlNodePtr node) { - virTristateBool fullscreen =3D VIR_TRISTATE_BOOL_NO; + virTristateBool fullscreen; if (virXMLPropTristateBool(node, "fullscreen", VIR_XML_PROP_NONE, &fullscreen) < 0) @@ -12662,7 +12662,7 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphics= Def *def, g_autofree xmlNodePtr *node_list =3D NULL; int n =3D 0; size_t i =3D 0; - virTristateBool autoport =3D VIR_TRISTATE_BOOL_NO; + virTristateBool autoport; xmlNodePtr cur; VIR_XPATH_NODE_AUTORESTORE(ctxt) --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315160; cv=none; d=zohomail.com; s=zohoarc; b=DM0BSXydLfkQdG81zg8DqYaSS8Gc5QHbpB8HqQZxLYgrYXQe2QrMpW2kJ+LPHVNO1EJZSHoIhuyD0mNggrS1yQv0QH9z06EkYfD9McYfDqqOdNJelL/JOnNErQhqZgOkQrqyev7TShGIgMXojsvQxWP729yDk4zyCfEoJA/8ScQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315160; 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=S/2zyZ5WPF7AjIbmusAZlFZU8lxwFGgA4v0gp7ZW9s0=; b=ZvGMTtM8bPQSBNGztdgBdBXslR7bXpL+RLDfMQu5cL1OAa+M1p/Jr6qGhgYQJglnBWIs2PFhn62b7Dfcg5+kX2jjWKpF5ABpbd+N+9xZcICIPmtFmoH9qS2cWl9nsFHiIDs1UhdSCeNKS7eU14myD4vBIac3erbbLnBK+pjcb0Q= 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 1620315160065214.97359734251393; Thu, 6 May 2021 08:32:40 -0700 (PDT) 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-456-Mgp-h85SNHizn_0kg0p7ew-1; Thu, 06 May 2021 11:31:38 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F02DB6D5B2; Thu, 6 May 2021 15:31:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D21D65D6AC; Thu, 6 May 2021 15:31:29 +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 958915535E; Thu, 6 May 2021 15:31:29 +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 146FVN94011452 for ; Thu, 6 May 2021 11:31:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id BE5C81045E8C; Thu, 6 May 2021 15:31:23 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EFC010190A7 for ; Thu, 6 May 2021 15:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315158; 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=S/2zyZ5WPF7AjIbmusAZlFZU8lxwFGgA4v0gp7ZW9s0=; b=QigO+RX3c/FsK3mtUqSu80bqy8IFmRiuNltNoInsE5uL5JZim92YaBR7mBwQghz+SxgDbs 8FDcg3MbvX2cYIPkZ2ta40dXu/Mmp135eV4bgI3u+3gk1KMsE7EoZ9aM8mUjDH77p32Q5M HVRgUA9qP+OnE2iejThguaLZo8b9MWA= X-MC-Unique: Mgp-h85SNHizn_0kg0p7ew-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 12/17] virXMLPropTristateSwitch: Always initialize '@result' Date: Thu, 6 May 2021 17:31:04 +0200 Message-Id: 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.79 on 10.5.11.15 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" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. In two cases the code needed to be adjusted to preserve functionality. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 10 ++++++++-- src/util/virxml.c | 4 ++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ea99a4c40a..ce0ffc60ef 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17443,12 +17443,15 @@ virDomainFeaturesDefParse(virDomainDef *def, case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: case VIR_DOMAIN_FEATURE_SMM: { - virTristateSwitch state =3D VIR_TRISTATE_SWITCH_ON; + virTristateSwitch state; if (virXMLPropTristateSwitch(nodes[i], "state", VIR_XML_PROP_NONE, &state) < 0) return -1; + if (state =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + state =3D VIR_TRISTATE_SWITCH_ON; + def->features[val] =3D state; break; } @@ -17770,7 +17773,7 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; for (i =3D 0; i < n; i++) { - virTristateSwitch state =3D VIR_TRISTATE_SWITCH_ON; + virTristateSwitch state; int val =3D virDomainProcessCapsFeatureTypeFromString((const char = *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -17783,6 +17786,9 @@ virDomainFeaturesDefParse(virDomainDef *def, &state) < 0) return -1; + if (state =3D=3D VIR_TRISTATE_SWITCH_ABSENT) + state =3D VIR_TRISTATE_SWITCH_ON; + def->caps_features[val] =3D state; } VIR_FREE(nodes); diff --git a/src/util/virxml.c b/src/util/virxml.c index d9bc5199b3..8e28629e9a 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -630,6 +630,8 @@ virXMLPropTristateBool(xmlNodePtr node, * @result: The returned value * * Convenience function to return value of an on / off attribute. + * In case when the property is missing @result is initialized to + * VIR_TRISTATE_SWITCH_ABSENT. * * Returns 1 in case of success in which case @result is set, * or 0 if the attribute is not present, @@ -643,6 +645,8 @@ virXMLPropTristateSwitch(xmlNodePtr node, { flags |=3D VIR_XML_PROP_NONZERO; + *result =3D VIR_TRISTATE_SWITCH_ABSENT; + return virXMLPropEnumInternal(node, name, virTristateSwitchTypeFromStr= ing, flags, result); } --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315193; cv=none; d=zohomail.com; s=zohoarc; b=dPCZb4akPWztH604hg+RnWEc6Q+1q6jDcEKSnBQVJcejs30FKiVmXY/0DoQe3nudfcaQkPfoCf3Id/gcBWf/CuTeL3OhsoPr43EJyIWwWfEQ3ST8/w5/11006EY1k1atrtQQnmZuJy5Gn2i4LH5E5YVNzDve5SxB4q06nmNQVUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315193; 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=WZx91em5esi5Dmw0F6r3c7Cl6lPLTT7cQs90JK8olKc=; b=X7wClPyUIRKDX8E39fKV0aDHtpMIvuMoMOJZXT4uN2sN7DnVnc3Pk90fyUbAJkwcfzCaGTPi1LB7Jqp/x8bDOXvIs1pgRlH7OxEV1Jjsg1xGzbfEpB2o8vJSTNeYC/Ud0IAdXTAqEr1wDLgyNeP4zG5rifLGGZvu/ii6f6llEmo= 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 16203151934756.328323272644411; Thu, 6 May 2021 08:33:13 -0700 (PDT) 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-391-UwisQHZiOM6HVMU5Jh0FNA-1; Thu, 06 May 2021 11:31:42 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D02CF100AA4E; Thu, 6 May 2021 15:31:32 +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 A76A05C582; Thu, 6 May 2021 15:31:32 +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 731EE1801263; Thu, 6 May 2021 15:31:32 +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 146FVOJT011464 for ; Thu, 6 May 2021 11:31:24 -0400 Received: by smtp.corp.redhat.com (Postfix) id D5545107914C; Thu, 6 May 2021 15:31:24 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3211A100EBAD for ; Thu, 6 May 2021 15:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315192; 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=WZx91em5esi5Dmw0F6r3c7Cl6lPLTT7cQs90JK8olKc=; b=R0XL+cw0cBnggmeNC9GMif5gIJTT0ZXxx1MEdtP0a0Lj7DzVq0EhUJdDlkDahWG0HjEvdw LfaT7pJKiO3EG7GvmxL1Y4B2Nb9nkJ1uHw6rURvqfjNL8ra7DyI/FTMfAQtD7detyhnwDS tlNw/c1cPo7lMt0N/OxqWg/yGMQLahM= X-MC-Unique: UwisQHZiOM6HVMU5Jh0FNA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 13/17] virDomainAudioCommonParse: Fix parsing of 'format' Date: Thu, 6 May 2021 17:31:05 +0200 Message-Id: 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.79 on 10.5.11.16 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" Commit 38180f87f5b converted the code to use virXMLPropEnum unfaithfully ommitting the check where 'format' must be non-zero when parsed from the user. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ce0ffc60ef..d36ff536f4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13098,7 +13098,7 @@ virDomainAudioCommonParse(virDomainAudioIOCommon *d= ef, if (virXMLPropEnum(settings, "format", virDomainAudioFormatTypeFromString, - VIR_XML_PROP_NONE, &def->format) < 0) + VIR_XML_PROP_NONZERO, &def->format) < 0) return -1; } --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315192; cv=none; d=zohomail.com; s=zohoarc; b=Vj2LiUpJ34L7MIXBdGkmW0FxfbK2VeX03i/2S58WSpYbYWb/rEt7OrzTJ9b3cfA2jNb+QoEnK6kw4yXs1LukRqbnhXwS4rzSU/ScXbXsvRXECXllJGVeG8h8o3eInHjXoEGSfjm5J5q1eEYI8mlS2RJ9V5acxgiV+yRKE3Ujyno= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315192; 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=ftq+qlQLMwAxZHGyyUsCcZNTO+KsFRfTG4atD8tB0Jc=; b=IiU+8ossbkMcAh0wlg3ES7W+wnLwCigqCfstSt3CTOHxL3NoqnITwOD5HV2QeBC3tAcmcXbdOyfNHojo+Jn6F27euDu7CO/XH9zSnqiBZTlMBvGVvBrdVX09iu+Y9FmWwu3rbw+CIzAJyuB8j/iN5Ql6XteplDebUMwLkt3HxgU= 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 1620315192318768.8528121149051; Thu, 6 May 2021 08:33:12 -0700 (PDT) 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-479-6RUla8qtMwiPlK7cC9og8g-1; Thu, 06 May 2021 11:31:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B688D107ACF2; Thu, 6 May 2021 15:31:35 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 97222690EF; Thu, 6 May 2021 15:31:35 +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 510955535E; Thu, 6 May 2021 15:31:35 +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 146FVPrR011478 for ; Thu, 6 May 2021 11:31:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id EA78010027A5; Thu, 6 May 2021 15:31:25 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4C0281079149 for ; Thu, 6 May 2021 15:31:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315190; 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=ftq+qlQLMwAxZHGyyUsCcZNTO+KsFRfTG4atD8tB0Jc=; b=FPkwX1clYJkQ+QCt534LKpfXo32pA7I9jDnmqsS2I5OPrep7EPZn7+Xqt4qSvLm9T+cGtC Leo3GDaVfSpkgaS7hguIJMYChTJFVD7gOjeXfIViGZH4stzPpRY92WwN61C7nTNSbaG/A5 las0rbSUSg2+x8LqSdj0ADzxYOPgX2Y= X-MC-Unique: 6RUla8qtMwiPlK7cC9og8g-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 14/17] virDomainVideoDefParseXML: Fix parsing of 'backend' Date: Thu, 6 May 2021 17:31:06 +0200 Message-Id: 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.79 on 10.5.11.11 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" Commit 8391cfbc2dbc converted the code to use virXMLPropEnum unfaithfully ommitting the check where 'backend' must be non-zero when parsed from the user. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d36ff536f4..bddc5eee26 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -14257,7 +14257,7 @@ virDomainVideoDefParseXML(virDomainXMLOption *xmlop= t, if ((driver =3D virXPathNode("./driver", ctxt))) { if (virXMLPropEnum(driver, "name", virDomainVideoBackendTypeFromString, - VIR_XML_PROP_NONE, &def->backend) < 0) + VIR_XML_PROP_NONZERO, &def->backend) < 0) return NULL; if (virDomainVirtioOptionsParseXML(driver, &def->virtio) < 0) return NULL; --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315154; cv=none; d=zohomail.com; s=zohoarc; b=g4OmaVNKdZ7pStFHZqBycQTT7O+XD8UE8SRcIwY17S9xmuS0wHkYLlzyMLda3VZQTNe+w7NsxtyjuShTqi6X3XLaOh5Pg7cS80/pR4Z8cf/0KoITEfnbXAsA34Ahs0XBHRFKE7QVJf9abF4hEKhJ5G9fILQ3n5MCW5xIRxLOXlE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315154; 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=lWHc52hKGZRgCbEADKO1iE3Ne73wRdrmUEJh7MgDLEc=; b=K+kMfpM0gfXyhCBNj5Ldace4QKVkIiPvHayjLbVEfou36vA04RVK4A8HdtOz/RRLebxnVtcom/RIGkGN9q9e54hZo52H7ZGMiQd7A6XudIs433AsNpyHHpIf+zP07UZShcMdAB+pZ6Sk3jGf0HkYBCs6JEyOna+g2W+PfNr4IdQ= 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 1620315154772628.1420107551432; Thu, 6 May 2021 08:32:34 -0700 (PDT) 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-39-qudFFavEPPG4xEUF7qUp3w-1; Thu, 06 May 2021 11:31:39 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 26ED793A80E; Thu, 6 May 2021 15:31:29 +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 CBBD82B6D4; Thu, 6 May 2021 15:31:28 +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 8BCA1180C69B; Thu, 6 May 2021 15:31:28 +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 146FVRSn011506 for ; Thu, 6 May 2021 11:31:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 15EBB10016F8; Thu, 6 May 2021 15:31:27 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67BBB1043293 for ; Thu, 6 May 2021 15:31:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315153; 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=lWHc52hKGZRgCbEADKO1iE3Ne73wRdrmUEJh7MgDLEc=; b=G2RWG23R0KNm9ougLNziiH7rt6lA9EcxjJfVQHJR2GBrtV94rq8WRtF/LTkLvbsacRvSCR /ct8yhV15OYJSrQb221Y6v+tTAoQ2NrzMYhNr6HAyPOL2v726zyuHKFeQXmSeJkw6zJ3V+ IL+Vyy2HScKcj+y28VGqEx3TGCIoSMQ= X-MC-Unique: qudFFavEPPG4xEUF7qUp3w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/17] util: xml: Introduce virXMLPropEnumDefault Date: Thu, 6 May 2021 17:31:07 +0200 Message-Id: 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.23 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" The helper is almost identical to virXMLPropEnum but it allows to pass a default value to initialize the result to. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virxml.c | 30 ++++++++++++++++++++++++++++++ src/util/virxml.h | 11 +++++++++++ 3 files changed, 42 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9f761c2c00..1b12c49018 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -3550,6 +3550,7 @@ virXMLNodeToString; virXMLParseHelper; virXMLPickShellSafeComment; virXMLPropEnum; +virXMLPropEnumDefault; virXMLPropInt; virXMLPropString; virXMLPropStringLimit; diff --git a/src/util/virxml.c b/src/util/virxml.c index 8e28629e9a..3ad596b3e2 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -827,6 +827,36 @@ virXMLPropULongLong(xmlNodePtr node, } +/** + * virXMLPropEnumDefault: + * @node: XML dom node pointer + * @name: Name of the property (attribute) to get + * @strToInt: Conversion function to turn enum name to value. Expected to + * return negative value on failure. + * @flags: Bitwise or of virXMLPropFlags + * @result: The returned value + * @defaultResult: default value set to @result in case the property is mi= ssing + * + * Convenience function to return value of an enum attribute. + * + * Returns 1 in case of success in which case @result is set, + * or 0 if the attribute is not present, + * or -1 and reports an error on failure. + */ +int +virXMLPropEnumDefault(xmlNodePtr node, + const char* name, + int (*strToInt)(const char*), + virXMLPropFlags flags, + unsigned int *result, + unsigned int defaultResult) +{ + *result =3D defaultResult; + + return virXMLPropEnumInternal(node, name, strToInt, flags, result); +} + + /** * virXMLPropEnum: * @node: XML dom node pointer diff --git a/src/util/virxml.h b/src/util/virxml.h index 939d2482cb..ed02abd2e9 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -152,6 +152,17 @@ virXMLPropEnum(xmlNodePtr node, ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4); +int +virXMLPropEnumDefault(xmlNodePtr node, + const char* name, + int (*strToInt)(const char*), + virXMLPropFlags flags, + unsigned int *result, + unsigned int defaultResult) + ATTRIBUTE_NONNULL(0) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) + ATTRIBUTE_NONNULL(4); + + /* Internal function; prefer the macros below. */ xmlDocPtr virXMLParseHelper(int domcode, --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315136; cv=none; d=zohomail.com; s=zohoarc; b=BXIOCYUdd+V2cqt/2e8YeKcxcMlOyA9wKFOukrgkwnxxpTREfcEq/rkdLugHtVEqBXCJL9NTWkXXptrh2ncUTbjQMs8E/hMqofAhI3tOb3SwMHit/jGCPWZ7dyfRqSPZwMNozOpf9Q/Y4lfVf2JHG+ZD1soLOpaKQliXtRSpmIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315136; 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=ROyK3yQHds7ecWUZGn/qHStZ0ZG8QsKT886z9gBkJ7k=; b=EEUJ38XzIuJPXBntGDUs9cq7kZSYbTDdzrdzt01p0BcQ+oF9lZq045T6qeF67wjuKwQYSOGWaK+zHR0pBBGONSVsbMy6vHB2/5kjrElwLUAzKrQOv5hkqTYtY+xL11wKGUwOrKeyaJgnVxGD+rSs65VIEVdTGmvk4uTXXgKc2QY= 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 1620315136702751.8737926560336; Thu, 6 May 2021 08:32:16 -0700 (PDT) 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-311-8pqBmpotOkyNbdFXNIHcIg-1; Thu, 06 May 2021 11:31:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09AE2189DF7E; Thu, 6 May 2021 15:31:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DB2E3690EF; Thu, 6 May 2021 15:31:31 +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 9BBFF5535E; Thu, 6 May 2021 15:31:31 +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 146FVSL9011521 for ; Thu, 6 May 2021 11:31:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F3CC10023AB; Thu, 6 May 2021 15:31:28 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C41F10016F8 for ; Thu, 6 May 2021 15:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315135; 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=ROyK3yQHds7ecWUZGn/qHStZ0ZG8QsKT886z9gBkJ7k=; b=QM/MHmWOQDoiCfulme4dS5u9t3Fc2tCqUZ15pzLwAT6VxeksPiB7SnlXupI7QYXyJV7ju3 4ETIAe52B+yCYIPFXsi/im67O5MfIV8RETISk3oLTp1EH37Mt6/RbuCuAFYIxEjpdNVxLb tcuWXlSVRjlUwdYg7K35UH0/Yv/ll0s= X-MC-Unique: 8pqBmpotOkyNbdFXNIHcIg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/17] conf: domain: Convert virXMLPropEnum to virXMLPropEnumDefault where we set defaults Date: Thu, 6 May 2021 17:31:08 +0200 Message-Id: <55351d798d260fbd52069cafecc7f96189d45282.1620314826.git.pkrempa@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.79 on 10.5.11.11 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 few cases where we set a default value when using virXMLPropEnum which can be converted to virXMLPropEnumDefault. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 74 +++++++++++++++++++++++------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bddc5eee26..e8632e4d73 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9083,11 +9083,9 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, ctxt->node =3D node; - /* defaults */ - def->device =3D VIR_DOMAIN_DISK_DEVICE_DISK; - - if (virXMLPropEnum(node, "device", virDomainDiskDeviceTypeFromString, - VIR_XML_PROP_NONE, &def->device) < 0) + if (virXMLPropEnumDefault(node, "device", virDomainDiskDeviceTypeFromS= tring, + VIR_XML_PROP_NONE, &def->device, + VIR_DOMAIN_DISK_DEVICE_DISK) < 0) return NULL; if (virXMLPropEnum(node, "model", virDomainDiskModelTypeFromString, @@ -11171,10 +11169,11 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceD= ef *def, xmlXPathContextPtr ctxt, unsigned int flags) { - virDomainChrSourceModeType mode =3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; + virDomainChrSourceModeType mode; - if (virXMLPropEnum(source, "mode", virDomainChrSourceModeTypeFromStrin= g, - VIR_XML_PROP_NONE, &mode) < 0) + if (virXMLPropEnumDefault(source, "mode", virDomainChrSourceModeTypeFr= omString, + VIR_XML_PROP_NONE, &mode, + VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) < 0) return -1; def->data.tcp.listen =3D mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; @@ -11208,10 +11207,11 @@ static int virDomainChrSourceDefParseUDP(virDomainChrSourceDef *def, xmlNodePtr source) { - virDomainChrSourceModeType mode =3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; + virDomainChrSourceModeType mode; - if (virXMLPropEnum(source, "mode", virDomainChrSourceModeTypeFromStrin= g, - VIR_XML_PROP_NONE, &mode) < 0) + if (virXMLPropEnumDefault(source, "mode", virDomainChrSourceModeTypeFr= omString, + VIR_XML_PROP_NONE, &mode, + VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) < 0) return -1; if (mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT && @@ -11233,10 +11233,11 @@ virDomainChrSourceDefParseUnix(virDomainChrSource= Def *def, xmlNodePtr source, xmlXPathContextPtr ctxt) { - virDomainChrSourceModeType mode =3D VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT; + virDomainChrSourceModeType mode; - if (virXMLPropEnum(source, "mode", virDomainChrSourceModeTypeFromStrin= g, - VIR_XML_PROP_NONE, &mode) < 0) + if (virXMLPropEnumDefault(source, "mode", virDomainChrSourceModeTypeFr= omString, + VIR_XML_PROP_NONE, &mode, + VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) < 0) return -1; def->data.nix.listen =3D mode =3D=3D VIR_DOMAIN_CHR_SOURCE_MODE_BIND; @@ -17426,11 +17427,12 @@ virDomainFeaturesDefParse(virDomainDef *def, break; case VIR_DOMAIN_FEATURE_CAPABILITIES: { - virDomainCapabilitiesPolicy policy =3D VIR_DOMAIN_CAPABILITIES= _POLICY_DEFAULT; + virDomainCapabilitiesPolicy policy; - if (virXMLPropEnum(nodes[i], "policy", - virDomainCapabilitiesPolicyTypeFromString, - VIR_XML_PROP_NONE, &policy) < 0) + if (virXMLPropEnumDefault(nodes[i], "policy", + virDomainCapabilitiesPolicyTypeFromS= tring, + VIR_XML_PROP_NONE, &policy, + VIR_DOMAIN_CAPABILITIES_POLICY_DEFAU= LT) < 0) return -1; def->features[val] =3D policy; @@ -17465,10 +17467,11 @@ virDomainFeaturesDefParse(virDomainDef *def, break; case VIR_DOMAIN_FEATURE_IOAPIC: { - virDomainIOAPIC driver =3D VIR_DOMAIN_IOAPIC_NONE; + virDomainIOAPIC driver; - if (virXMLPropEnum(nodes[i], "driver", virDomainIOAPICTypeFrom= String, - VIR_XML_PROP_NONZERO, &driver) < 0) + if (virXMLPropEnumDefault(nodes[i], "driver", virDomainIOAPICT= ypeFromString, + VIR_XML_PROP_NONZERO, &driver, + VIR_DOMAIN_IOAPIC_NONE) < 0) return -1; def->features[val] =3D driver; @@ -17502,10 +17505,11 @@ virDomainFeaturesDefParse(virDomainDef *def, break; case VIR_DOMAIN_FEATURE_CFPC: { - virDomainCFPC value =3D VIR_DOMAIN_CFPC_NONE; + virDomainCFPC value; - if (virXMLPropEnum(nodes[i], "value", virDomainCFPCTypeFromStr= ing, - VIR_XML_PROP_NONZERO, &value) < 0) + if (virXMLPropEnumDefault(nodes[i], "value", virDomainCFPCType= FromString, + VIR_XML_PROP_NONZERO, &value, + VIR_DOMAIN_CFPC_NONE) < 0) return -1; def->features[val] =3D value; @@ -17513,10 +17517,11 @@ virDomainFeaturesDefParse(virDomainDef *def, } case VIR_DOMAIN_FEATURE_SBBC: { - virDomainSBBC value =3D VIR_DOMAIN_SBBC_NONE; + virDomainSBBC value; - if (virXMLPropEnum(nodes[i], "value", virDomainSBBCTypeFromStr= ing, - VIR_XML_PROP_NONZERO, &value) < 0) + if (virXMLPropEnumDefault(nodes[i], "value", virDomainSBBCType= FromString, + VIR_XML_PROP_NONZERO, &value, + VIR_DOMAIN_SBBC_NONE) < 0) return -1; def->features[val] =3D value; @@ -17524,10 +17529,11 @@ virDomainFeaturesDefParse(virDomainDef *def, } case VIR_DOMAIN_FEATURE_IBS: { - virDomainIBS value =3D VIR_DOMAIN_IBS_NONE; + virDomainIBS value; - if (virXMLPropEnum(nodes[i], "value", virDomainIBSTypeFromStri= ng, - VIR_XML_PROP_NONZERO, &value) < 0) + if (virXMLPropEnumDefault(nodes[i], "value", virDomainIBSTypeF= romString, + VIR_XML_PROP_NONZERO, &value, + VIR_DOMAIN_IBS_NONE) < 0) return -1; def->features[val] =3D value; @@ -18049,10 +18055,10 @@ virDomainVcpuParse(virDomainDef *def, vcpus =3D maxvcpus; } - def->placement_mode =3D VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC; - if (virXMLPropEnum(vcpuNode, "placement", - virDomainCpuPlacementModeTypeFromString, - VIR_XML_PROP_NONE, &def->placement_mode) < 0) + if (virXMLPropEnumDefault(vcpuNode, "placement", + virDomainCpuPlacementModeTypeFromString, + VIR_XML_PROP_NONE, &def->placement_mode, + VIR_DOMAIN_CPU_PLACEMENT_MODE_STATIC) < = 0) return -1; if (def->placement_mode !=3D VIR_DOMAIN_CPU_PLACEMENT_MODE_AUTO) { --=20 2.30.2 From nobody Sat May 18 06:31:29 2024 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=1620315105; cv=none; d=zohomail.com; s=zohoarc; b=apmS071CXyJ2kHygSDpbmGP7pPiaCuJxl1LtlC/F4zspzOfG/BVNgEZRaIWPw3fKWyof/oRzVnmMsltaGXfAjZWb9fO0O4g/B6zjgh2n6nx782F8L33MAPAE1KoLwbkxxIRqifqIlvPrMso7PKwj0rb9zMvNnz6VWGmak6x9RSQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1620315105; 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=97aLDfED8yu1QYyFF82U5HiCKhsGUawrmz8QTSFppZ0=; b=bEbOLAHRNY0OqVQ0FzvutQp9jr6pw7yO/qyknC8p58EMyo8QQ7XflQQvNLTuFCWWq1q6DjiBX025Z6xbfkkbedUbJiXbqQ94NFezKOz6uZx/8/3f/aoqKZ94zi3yRtQjsFHrzD6wxeuPu/GhPw75zI85lS9FJloTOVeW5bvNeUg= 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 1620315105408714.418742014494; Thu, 6 May 2021 08:31:45 -0700 (PDT) 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-153-UJaPCdhiOYqx7Hya2mzYGA-1; Thu, 06 May 2021 11:31:40 -0400 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 F082E93A826; Thu, 6 May 2021 15:31:31 +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 9BF5A1059178; Thu, 6 May 2021 15:31:31 +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 5A868180140D; Thu, 6 May 2021 15:31:31 +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 146FVTiv011540 for ; Thu, 6 May 2021 11:31:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 423C4105B204; Thu, 6 May 2021 15:31:29 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B24C1037E88 for ; Thu, 6 May 2021 15:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620315103; 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=97aLDfED8yu1QYyFF82U5HiCKhsGUawrmz8QTSFppZ0=; b=JXxnh1CorMMYJR+22A0DiJyZu1NqhJIykpgUfOaxX7hBOdzhLrJg1m+r9IPGQepXVlLUob Sg+aMvFNySNmMjwvz6JVLTyQTL39dU2W5VTekLVpuT465tbf9J+DEDl5/r7z3DuU2RbPdD Nus757nqf50u9EUYQX9k4m1YOTDxbNw= X-MC-Unique: UJaPCdhiOYqx7Hya2mzYGA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 17/17] virXMLPropEnum: Always initialize '@result' Date: Thu, 6 May 2021 17:31:09 +0200 Message-Id: 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" Compilers aren't able to see whether @result is set or not and thus don't warn of a potential use of uninitialized value. Always set @result to prevent uninitialized use. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 3ad596b3e2..8dcece704a 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -562,12 +562,15 @@ virXMLPropEnumInternal(xmlNodePtr node, const char* name, int (*strToInt)(const char*), virXMLPropFlags flags, - unsigned int *result) + unsigned int *result, + unsigned int defaultResult) { g_autofree char *tmp =3D NULL; int ret; + *result =3D defaultResult; + if (!(tmp =3D virXMLPropString(node, name))) { if (!(flags & VIR_XML_PROP_REQUIRED)) return 0; @@ -615,10 +618,8 @@ virXMLPropTristateBool(xmlNodePtr node, { flags |=3D VIR_XML_PROP_NONZERO; - *result =3D VIR_TRISTATE_BOOL_ABSENT; - return virXMLPropEnumInternal(node, name, virTristateBoolTypeFromStrin= g, - flags, result); + flags, result, VIR_TRISTATE_BOOL_ABSENT); } @@ -645,10 +646,8 @@ virXMLPropTristateSwitch(xmlNodePtr node, { flags |=3D VIR_XML_PROP_NONZERO; - *result =3D VIR_TRISTATE_SWITCH_ABSENT; - return virXMLPropEnumInternal(node, name, virTristateSwitchTypeFromStr= ing, - flags, result); + flags, result, VIR_TRISTATE_SWITCH_ABSEN= T); } @@ -851,9 +850,7 @@ virXMLPropEnumDefault(xmlNodePtr node, unsigned int *result, unsigned int defaultResult) { - *result =3D defaultResult; - - return virXMLPropEnumInternal(node, name, strToInt, flags, result); + return virXMLPropEnumInternal(node, name, strToInt, flags, result, def= aultResult); } @@ -867,6 +864,7 @@ virXMLPropEnumDefault(xmlNodePtr node, * @result: The returned value * * Convenience function to return value of an enum attribute. + * @result is initialized to 0 on error or if the element is not found. * * Returns 1 in case of success in which case @result is set, * or 0 if the attribute is not present, @@ -879,7 +877,7 @@ virXMLPropEnum(xmlNodePtr node, virXMLPropFlags flags, unsigned int *result) { - return virXMLPropEnumInternal(node, name, strToInt, flags, result); + return virXMLPropEnumInternal(node, name, strToInt, flags, result, 0); } --=20 2.30.2