From patchwork Mon Mar 25 12:35:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 782320 Delivered-To: patch@linaro.org Received: by 2002:a5d:4e01:0:b0:33e:7753:30bd with SMTP id p1csp1147064wrt; Mon, 25 Mar 2024 05:37:55 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWegdHLxnk+G2UuyyaQNLfNUqFi8T+8UmWlwVqNpgituflmmes1iX1nQRt3G0dOspkWQo4s5x6e9EjHTVQFh1y6 X-Google-Smtp-Source: AGHT+IHjpTw2/xC7RKlPETyiuBH5YMAcJ61OoVSdlOS7TJx56AMcI3wqZd2VgNNqZ7B+/CWeUx8N X-Received: by 2002:a05:6102:2322:b0:476:589f:c14b with SMTP id b2-20020a056102232200b00476589fc14bmr5064869vsa.6.1711370274773; Mon, 25 Mar 2024 05:37:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711370274; cv=none; d=google.com; s=arc-20160816; b=w+DsRQSRmcd5feilXDDoZ5awe1D3Nc3rFnrYVNoJNv2U46zKUZmlbPOj38Q31bmSgF Titn/h7gku1i41pgOVhkkJh+IvVGb/Yy87aWxzjG9WFQgsL5j7QV8Y7G+KegddWI5h+F n0bc82hbHPrdKgQP3zNXuPFxGr+EUVrqSmP/LEfLb/2EGTGcuIc2XSzj1nPZ2DYNVZk2 XqZBdZF1rUSJ8mv6EjUAv2sY0ifrDZc1+WpiWPD4g19+zeBHWL3dnyCNGKwm9AbSC0Yj UcVDZT53aTQ5PSXpiZ7B1bDpMqo8b0t7nZcawtAYgJuKFy9o7jVdBOZyKPzAHMXsAfQ+ 6E9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=4aVB8aQfFHBTbOCLmq+XJCLN+ZOpZZJ/7MtfrbF8pCw=; fh=PnYt+qEB9tAfMKoqBm2xjKOFpYyFFGPudh5cVIoieJM=; b=aFsQBic7bUNeEwwhHQLAOsTnzDvs+K4D78qkfSX8YLWlDBH0CZwch2MGThHjbTdIx0 0S61/ckuhqI4JBattceUaz1qVPzssXBJaxe4Uw2x1Pb5LyNp6fB8OyhyM+BEzFGTmXvo wXIwr0sm6wMNnZvLSUuspENL3+YZ5nhdLpaTKS6pJM9rH+4zsFnGXDTlWB9wM0F8WwNg 6X2cuijyXJSUCTJq26G8Lx/niJRztQoPTMKGoqH3DCQdMhiXrS5Isr/8Dzar7qmlkH1C 3JZprfmXTx1DaSpT2McXEmH4qgLa5wKAb0mOHD/4468Qei0RsdGfGWd0+4i+ZbbmpaSD FT3A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w9yF66Wd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id i13-20020a05620a0a0d00b00789efde4910si5185097qka.163.2024.03.25.05.37.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Mar 2024 05:37:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w9yF66Wd; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rojYX-0002JX-IL; Mon, 25 Mar 2024 08:36:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rojYU-0002Ht-9n for qemu-devel@nongnu.org; Mon, 25 Mar 2024 08:35:58 -0400 Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rojYS-0005dd-7v for qemu-devel@nongnu.org; Mon, 25 Mar 2024 08:35:57 -0400 Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-4148c650bc7so151855e9.2 for ; Mon, 25 Mar 2024 05:35:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711370154; x=1711974954; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4aVB8aQfFHBTbOCLmq+XJCLN+ZOpZZJ/7MtfrbF8pCw=; b=w9yF66WdwsE+kArJ66Pb6xkLwB9g3nGczm/cJOZDvW3tqOlgy2/rqEy0AI97C0k7FN ku+y1cYcrX3YZKsOafkDsbsBU5+9iLOT7JXENrI2scuhD2qwswe7s1rOyRsHhypfNhWR sCFbB9gSQ3ww2G+7nnXmm2xV59Ob9v3LPpPxRNBhCQM+gwCQV4RiZG1mVhKqMllR+n9C NUMx159Sw3REk/2cPJ97CE93mHMmcsWkbAzdOd0TowosL2jHYgh+H5yPBWLJI31aoynk FOfC3K+8YtCIWQNxMozhxuWD0U42oSxr6zNhF4ubTCCdDtJA9p1WscDOk214N5/lDPt9 7csQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711370154; x=1711974954; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4aVB8aQfFHBTbOCLmq+XJCLN+ZOpZZJ/7MtfrbF8pCw=; b=d6Quj62dOn56qTzFKFeLTeQtfGn60wrTSfwy5dhTb4h9jQmpdA2sNP7VkB4vfOYyBA nC2ehMlecMynk/appXtEZOIqHbVIplBuT7KX4Cxqqxq/FeSUpx32hbSy0Rziqnhfi+9L PWb6WG36xCKs358zGKPF/r5Zp7/+pfy/Lv+y4dZ1o2XZgBtpzbvV0RiYsddTqAXMA+oo dR98RK8aQNbFeOFrQ1xRvTsk6/gYU6Hm/9JxFZhEoVVkKXPCyVxlE7PVeoZ6ek2gKpyT HLPVcBLb75QcG88Vi50ABMJmLhslU1+R0avkG8b8+IBsF9jBibv1kPwdgj/TemnGFXWo yBbA== X-Gm-Message-State: AOJu0Ywmm4334gY3/SMbUZgk9MGq3hB2Yvg3667z6BY0Agl9ovzHhVKb zUOxgzATmTF0v0EMpLIWvZkbpCZk7nKD/v+UazG7pHI0P9OyTYqxojNQGSLPDzC5sERjte7jQ2o j X-Received: by 2002:a05:600c:1547:b0:413:ff10:cee with SMTP id f7-20020a05600c154700b00413ff100ceemr4997308wmg.13.1711370154700; Mon, 25 Mar 2024 05:35:54 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id o19-20020a05600c339300b00414041032casm2303877wmp.1.2024.03.25.05.35.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 05:35:54 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 6/7] tests/unit/test-throttle: Avoid unintended integer division Date: Mon, 25 Mar 2024 12:35:49 +0000 Message-Id: <20240325123550.1991693-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240325123550.1991693-1-peter.maydell@linaro.org> References: <20240325123550.1991693-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x336.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org In test_compute_wait() we do double units = bkt.max / 10; which does an integer division and then assigns it to a double variable, and similarly later on in the expression for an assertion. Use 10.0 so that we do a floating point division and calculate the exact value, rather than doing an integer division. Spotted by Coverity. Resolves: Coverity CID 1432564 Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson Reviewed-by: Thomas Huth Reviewed-by: Philippe Mathieu-Daudé Message-id: 20240312183810.557768-7-peter.maydell@linaro.org --- tests/unit/test-throttle.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/test-throttle.c b/tests/unit/test-throttle.c index 2146cfacd36..24032a02667 100644 --- a/tests/unit/test-throttle.c +++ b/tests/unit/test-throttle.c @@ -127,13 +127,13 @@ static void test_compute_wait(void) bkt.avg = 10; bkt.max = 200; for (i = 0; i < 22; i++) { - double units = bkt.max / 10; + double units = bkt.max / 10.0; bkt.level += units; bkt.burst_level += units; throttle_leak_bucket(&bkt, NANOSECONDS_PER_SECOND / 10); wait = throttle_compute_wait(&bkt); g_assert(double_cmp(bkt.burst_level, 0)); - g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10)); + g_assert(double_cmp(bkt.level, (i + 1) * (bkt.max - bkt.avg) / 10.0)); /* We can do bursts for the 2 seconds we have configured in * burst_length. We have 100 extra milliseconds of burst * because bkt.level has been leaking during this time.