From nobody Sun Feb 8 16:05:55 2026 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=1666620949; cv=none; d=zohomail.com; s=zohoarc; b=iKTgykfUfs7nRhK/wHgbzi/nDKPJf0dU5IFdQG8p8qj72t3AgQQd9sRDt8YbDPfNdhbadsNxm0rzPzyI0G6fWSGilQXnjip6eJL4PH1kmX3MzeKafLH1B43UmSQC+k+EdaiFJCJnuU7mHU5GL/ur/jStna+cvIkmwqFJE+ACeOM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666620949; 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=24ip7FlkwSJISyPqE5Kr9Xe/EipOz86R20wiAZiFe3c=; b=NPjyq2GlrztYPBv/CyNEdPbsTLauv07mp9LiLS+EI/iJeR2EHD8ocgcDaCz5bpBMYVvvlBseXHomTmfJ1Ax7+wosopsgzubN9ljugFLGs9Pw+XyxJHPhATFnWLyrdHGbZ21DQBISyP1ZQ77ftI5dNppxqPuC/LqcENcd9x7Ds+M= 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) 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 1666620949954669.7068030910048; Mon, 24 Oct 2022 07:15:49 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-224-npc_cgOAM5WXqKUdYFmiKg-1; Mon, 24 Oct 2022 10:15:43 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DA6CA3C11060; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id C28CE1121315; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id B455719465A0; Mon, 24 Oct 2022 14:15:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 79779194658F for ; Mon, 24 Oct 2022 14:15:20 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 69F3A40C2089; Mon, 24 Oct 2022 14:15:20 +0000 (UTC) Received: from speedmetal.lan (ovpn-208-27.brq.redhat.com [10.40.208.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB52140C2064 for ; Mon, 24 Oct 2022 14:15:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666620948; 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=24ip7FlkwSJISyPqE5Kr9Xe/EipOz86R20wiAZiFe3c=; b=KeC6XFHQofvgas1N49Cf15m3J1h4c5BZ5dT+07bDhO9yK5d6B5WUjeWp7pQLM1Cb8VP9Cw HcZ/5eWWcWtgxPZV7Vj9rIe1kON0JNhb+/KH88oh3N13gH3bP34KvWtcLQRePsJJxjdMGB cX4UQeBxzgKmazv9yt/DoY7TlzUzr3Y= X-MC-Unique: npc_cgOAM5WXqKUdYFmiKg-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 18/43] util: xml: Reimplement virXPath(U)Int via virXPathEvalString Date: Mon, 24 Oct 2022 16:14:23 +0200 Message-Id: <36db07cd9eb839b07a7fdae7a3390d6500290519.1666619795.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666620950229100001 Content-Type: text/plain; charset="utf-8" Similarly to the refactor of virXPath(U)LongLong drop the ability to convert from the internal double value forcing the use of the 'string()' conversion. In case of 32 bit integers there's no problem with overflows, but we can implement the code identically to what we have in the other helpers. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/util/virxml.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 067fef8856..d885fc1680 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -149,7 +149,9 @@ virXPathLongBase(const char *xpath, * @ctxt: an XPath context * @value: the returned int value * - * Convenience function to evaluate an XPath number + * Convenience function to evaluate an XPath number. The @xpath expression + * must ensure that the evaluated value is returned as a string (use the + * 'string()' conversion in the expression). * * Returns 0 in case of success in which case @value is set, * or -1 if the XPath evaluation failed or -2 if the @@ -160,15 +162,14 @@ virXPathInt(const char *xpath, xmlXPathContextPtr ctxt, int *value) { - long tmp; - int ret; + g_autoptr(xmlXPathObject) obj =3D NULL; - ret =3D virXPathLongBase(xpath, ctxt, 10, &tmp); - if (ret < 0) - return ret; - if ((int) tmp !=3D tmp) + if (!(obj =3D virXPathEvalString(xpath, ctxt))) + return -1; + + if (virStrToLong_i((char *) obj->stringval, NULL, 10, value) < 0) return -2; - *value =3D tmp; + return 0; } @@ -230,28 +231,29 @@ virXPathULongBase(const char *xpath, * virXPathUInt: * @xpath: the XPath string to evaluate * @ctxt: an XPath context - * @value: the returned int value + * @value: the returned unsigned int value * - * Convenience function to evaluate an XPath number + * Convenience function to evaluate an XPath number. The @xpath expression + * must ensure that the evaluated value is returned as a string (use the + * 'string()' conversion in the expression). * * Returns 0 in case of success in which case @value is set, * or -1 if the XPath evaluation failed or -2 if the - * value doesn't have an int format. + * value doesn't have an unsigned int format. */ int virXPathUInt(const char *xpath, xmlXPathContextPtr ctxt, unsigned int *value) { - unsigned long tmp; - int ret; + g_autoptr(xmlXPathObject) obj =3D NULL; - ret =3D virXPathULongBase(xpath, ctxt, 10, &tmp); - if (ret < 0) - return ret; - if ((unsigned int) tmp !=3D tmp) + if (!(obj =3D virXPathEvalString(xpath, ctxt))) + return -1; + + if (virStrToLong_ui((char *) obj->stringval, NULL, 10, value) < 0) return -2; - *value =3D tmp; + return 0; } --=20 2.37.3