From patchwork Wed Oct 11 10:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 731951 Delivered-To: patch@linaro.org Received: by 2002:a5d:54d1:0:b0:31d:da82:a3b4 with SMTP id x17csp329624wrv; Wed, 11 Oct 2023 03:44:28 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/0fz0nfqGc/jXMUkBezC0gamruGn8AY+Wsn9eLAO5+cAzpDHen+Vz1H5cYQbTfs7mXvvQ X-Received: by 2002:a05:620a:29c9:b0:777:6d:b877 with SMTP id s9-20020a05620a29c900b00777006db877mr15468068qkp.68.1697021068009; Wed, 11 Oct 2023 03:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697021067; cv=none; d=google.com; s=arc-20160816; b=YONlal5zNYSRQqwM0dhHV4VKJOG5n8/LnqBztWIW7ZIe5ce0FAvt0Xlr98hqQN3uTE c3mXRmC99N+ISaKd7yonql0xgxd/G8NYE6L5ZbOukRrBycyZrHfJnXqQY6TW8IRE5fPf 6hi3dZVV6/N/J6nAxSo6EdDoFuf7ievwi2pCPXhKoLVZWO+XqNC55r9hsDcOZfLcC2eE M6yKEw1WvFgHersVuJcQuzLuu2m7s+/o903mv0+6BqdcTnI9cnl4TmC1yh0wqFgi/lSs aEQK8RsC41r0Bq4yqHiNJ3eZD5faN0b55u/4sIrpXjf4dV2mPyDVFn70A6J9B4WMQed4 Vkzg== 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:cc:to :from:dkim-signature; bh=yf1R+Vby24DYe8++3MpeTUjuX+WlwLu5umzTar0tTFw=; fh=kyaHiEU+lIVT4poymSOoM0p0KZxXkvLW2auuM3J5H08=; b=1KBZe4fYh+d+ml4AXoVQ91SM/xNQdGfo+jzBDjBeLfyktGc/QQ6tuqLDd5bM2R4wRZ 90rGnSswi7GIwhHfVVA/KieFGo8TFBppyFgWP6v5uwHRxYmfJjh8vzanXeAy4k7q1PPs rODsZ8yWEN3WH/GgncKOfUaaEseu4QiRDZ51cMQDpkas4QjJ6bE5ON9zqO0IDPzuD0r5 k0icHs+QeZ2oIQ4aqktJNxClQDaKWqfdwpwm+58UitDXJ8txPAwOBHjvCEu+FL2k/RbB nTHX5wsmWpVSZdnEUR5qhItmTPx2+fvWQ+7kD7RTwn8C8Aa9NHokexuvv5V9Gvpr+Xuk Fs1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YeVqIpef; 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 dp7-20020a05620a2b4700b0076eed2a7335si9197348qkb.57.2023.10.11.03.44.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 11 Oct 2023 03:44:27 -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=YeVqIpef; 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 1qqWgk-0008BR-4k; Wed, 11 Oct 2023 06:43:38 -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 1qqWgi-00089f-61 for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:43:36 -0400 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qqWgf-0007ep-JM for qemu-devel@nongnu.org; Wed, 11 Oct 2023 06:43:35 -0400 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-406619b53caso62326275e9.1 for ; Wed, 11 Oct 2023 03:43:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697021011; x=1697625811; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yf1R+Vby24DYe8++3MpeTUjuX+WlwLu5umzTar0tTFw=; b=YeVqIpef26BKWs8iXB1Jcni/siKmHcFUidjZE0hzSJtuYE8dwfVW+ZJeaSnO75aSi+ Y96PeHDi0ZhrcZXs0vfVeQvhyA+rIlpRv5g6n2wdY/uqHPYV+BbpJyuJtAcpZndB5b4c /YGCCxA066Zsl4QG8fhQetxUwuzWRm5V54a4nQoIDBphEsi5wKKTKpjZv1qevuEEF2BN FxOYBM3s8yJTsB30kTlHCHBT3kO4PBG4s2qm8YRFZsqQW8FMgeKuO0ApmsFKRDFkMt/s ik+vMARNMB5wgkyVL8V+cnyOLZncYTOPscjt7IUf5qZxNczoTyx46T8QusEGh0zYTBkv IuNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697021011; x=1697625811; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yf1R+Vby24DYe8++3MpeTUjuX+WlwLu5umzTar0tTFw=; b=jmZGiA2mkXjxciOfGWbA/EjPTOLSzlSo6NljNN5XHw0CffxUhR4sk4siNaw1Q7ZJBL P6VU2W+G2rl+t9aKWTs8gf2Jtp9/B5VuOVFBTilKUpMKDzIpKAcdBAyejh728sn83Pgj vwtmxNyJx8zP2XuRER3k5jaPg50rHETCFwCgc6PmmErcciAiO60+x2LJX5WYMO++4exw 64sZqvrZojkWuUzdNs9dNv8SSa97IRrUj9Y7HiLfJKpqAb01cX4TnOjlnR6gZOIKVTGi iI+pzgfspcSfLLeKJKjE1x/KlOsniLwyt7g/mexzbmmOXJgwMvfFtk5k2EGdadoJOJRh LSiw== X-Gm-Message-State: AOJu0Yyn6dfO9rqhJoHtx1RMoN6Unjf2H6XqGl+RXH6MjN5y1SA8vniY TA2nHJdnN9vVhrUwzlGjlbw/OLzvHv7Y8P/J16Y= X-Received: by 2002:a05:600c:3546:b0:406:8496:bd8b with SMTP id i6-20020a05600c354600b004068496bd8bmr16283352wmq.9.1697021011485; Wed, 11 Oct 2023 03:43:31 -0700 (PDT) Received: from zen.linaroharston ([85.9.250.243]) by smtp.gmail.com with ESMTPSA id s4-20020a5d6a84000000b00327bf4f2f14sm15126848wru.88.2023.10.11.03.43.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 03:43:31 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id A2A8A1FFBE; Wed, 11 Oct 2023 11:33:32 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Alexandre Iooss , Mahmoud Mandour Subject: [PULL 23/25] contrib/plugins: fix coverity warning in cache Date: Wed, 11 Oct 2023 11:33:27 +0100 Message-Id: <20231011103329.670525-24-alex.bennee@linaro.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011103329.670525-1-alex.bennee@linaro.org> References: <20231011103329.670525-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::332; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x332.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 Coverity complains that appends_stats_line can be fed a 0 leading to the undefined behaviour of a divide by 0. Fixes: CID 1519044 Fixes: CID 1519047 Signed-off-by: Alex Bennée Message-Id: <20231009164104.369749-24-alex.bennee@linaro.org> diff --git a/contrib/plugins/cache.c b/contrib/plugins/cache.c index 4fca3edd07..9e7ade3b37 100644 --- a/contrib/plugins/cache.c +++ b/contrib/plugins/cache.c @@ -535,15 +535,13 @@ static void caches_free(Cache **caches) } } -static void append_stats_line(GString *line, uint64_t l1_daccess, - uint64_t l1_dmisses, uint64_t l1_iaccess, - uint64_t l1_imisses, uint64_t l2_access, - uint64_t l2_misses) +static void append_stats_line(GString *line, + uint64_t l1_daccess, uint64_t l1_dmisses, + uint64_t l1_iaccess, uint64_t l1_imisses, + uint64_t l2_access, uint64_t l2_misses) { - double l1_dmiss_rate, l1_imiss_rate, l2_miss_rate; - - l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0; - l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0; + double l1_dmiss_rate = ((double) l1_dmisses) / (l1_daccess) * 100.0; + double l1_imiss_rate = ((double) l1_imisses) / (l1_iaccess) * 100.0; g_string_append_printf(line, "%-14" PRIu64 " %-12" PRIu64 " %9.4lf%%" " %-14" PRIu64 " %-12" PRIu64 " %9.4lf%%", @@ -554,8 +552,8 @@ static void append_stats_line(GString *line, uint64_t l1_daccess, l1_imisses, l1_iaccess ? l1_imiss_rate : 0.0); - if (use_l2) { - l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0; + if (l2_access && l2_misses) { + double l2_miss_rate = ((double) l2_misses) / (l2_access) * 100.0; g_string_append_printf(line, " %-12" PRIu64 " %-11" PRIu64 " %10.4lf%%", l2_access,