From nobody Sat Oct 5 21:49:47 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; spf=none (zohomail.com: 8.43.85.245 is neither permitted nor denied by domain of lists.libvirt.org) smtp.mailfrom=devel-bounces@lists.libvirt.org Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1706003417309769.8891538008925; Tue, 23 Jan 2024 01:50:17 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 468A11A54; Tue, 23 Jan 2024 04:50:16 -0500 (EST) Received: from lists.libvirt.org.85.43.8.in-addr.arpa (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id BB2391A28; Tue, 23 Jan 2024 04:41:58 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 4977B1941; Tue, 23 Jan 2024 04:29:01 -0500 (EST) Received: from mail.astralinux.ru (mail.astralinux.ru [217.74.38.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 0790C192D for ; Tue, 23 Jan 2024 04:28:58 -0500 (EST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id 1FBD0186A306; Tue, 23 Jan 2024 12:28:56 +0300 (MSK) Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id nIxMnG-WWjME; Tue, 23 Jan 2024 12:28:55 +0300 (MSK) Received: from localhost (localhost.localdomain [127.0.0.1]) by mail.astralinux.ru (Postfix) with ESMTP id C8DD7186A305; Tue, 23 Jan 2024 12:28:55 +0300 (MSK) Received: from mail.astralinux.ru ([127.0.0.1]) by localhost (rbta-msk-vsrv-mail01.astralinux.ru [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id k277EabVtAxg; Tue, 23 Jan 2024 12:28:55 +0300 (MSK) Received: from rbta-msk-lt-320952.astralinux.ru (unknown [10.177.20.81]) by mail.astralinux.ru (Postfix) with ESMTPSA id 67388186A304; Tue, 23 Jan 2024 12:28:55 +0300 (MSK) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.4 X-Virus-Scanned: amavisd-new at astralinux.ru From: Egor Makrushin To: devel@lists.libvirt.org Subject: [PATCH] Explicitly convert type to double to avoid losing precision Date: Tue, 23 Jan 2024 12:28:34 +0300 Message-Id: <20240123092834.14371-1-emakrushin@astralinux.ru> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-MailFrom: emakrushin@astralinux.ru X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 Message-ID-Hash: 5N6GEKBBLQ72OI4UI3SB4DJYJSADVGJT X-Message-ID-Hash: 5N6GEKBBLQ72OI4UI3SB4DJYJSADVGJT X-Mailman-Approved-At: Tue, 23 Jan 2024 09:41:12 -0500 CC: sdl.libvirt@linuxtesting.org, Egor Makrushin X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1706003418275100001 Division between integers will also be integer. Thus, to preserve fractional part explicitly convert first operand to double. Found by Linux Verification Center (linuxtesting.org) with SVACE. Fixes: 28d54aab05 ("examples: Introduce domtop") Signed-off-by: Egor Makrushin Reviewed-by: Martin Kletzander --- examples/c/domain/domtop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/c/domain/domtop.c b/examples/c/domain/domtop.c index dd35ec8661..65663a1c39 100644 --- a/examples/c/domain/domtop.c +++ b/examples/c/domain/domtop.c @@ -224,7 +224,7 @@ print_cpu_usage(size_t cpu, * performed has a bad effect on the precision, so instead of divi= ding * @now_params and @then_params by 1000 and then multiplying again= by * 100, we divide only once by 10 and get the same result. */ - usage =3D (now_params[pos].value.ul - then_params[pos].value.ul) / + usage =3D (double)(now_params[pos].value.ul - then_params[pos].val= ue.ul) / (now - then) / 10; =20 if (delim) --=20 2.30.2 _______________________________________________ Devel mailing list -- devel@lists.libvirt.org To unsubscribe send an email to devel-leave@lists.libvirt.org