From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id DD0C7A0548; Mon, 26 Apr 2021 13:20:21 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AB17541104; Mon, 26 Apr 2021 13:20:21 +0200 (CEST) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id D40B040140 for ; Mon, 26 Apr 2021 13:20:20 +0200 (CEST) IronPort-SDR: y+Rh1fp2tnfHgjEx4rkFq/Vmk0JERWOHZbOKUa9XETeuOlYzVoXWy9StZNDj4lqOh/NPog9ODE YdE2tbxw/kyQ== X-IronPort-AV: E=McAfee;i="6200,9189,9965"; a="260270613" X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="260270613" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 04:20:18 -0700 IronPort-SDR: iuX5bEwymfKuW9JEHgJitr6LDbESjl1N/Cpzxixr7UkNAQJh1iiThL1eBaFt59MFKEb5q8DpSO 9tkSXKyGkjFw== X-IronPort-AV: E=Sophos;i="5.82,252,1613462400"; d="scan'208";a="429358380" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.213.240.23]) ([10.213.240.23]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Apr 2021 04:20:17 -0700 To: "Min Hu (Connor)" , dev@dpdk.org Cc: xiaoyun.li@intel.com References: <1619005102-38437-1-git-send-email-humin29@huawei.com> From: Ferruh Yigit X-User: ferruhy Message-ID: Date: Mon, 26 Apr 2021 12:20:13 +0100 MIME-Version: 1.0 In-Reply-To: <1619005102-38437-1-git-send-email-humin29@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" On 4/21/2021 12:38 PM, Min Hu (Connor) wrote: > Variable total, which may be zero and result in segmentation fault. > > This patch fixed it. > > Fixes: 9b1249d9ff69 ("app/testpmd: support dumping socket memory") > Cc: stable@dpdk.org > > Signed-off-by: Min Hu (Connor) > --- > app/test-pmd/cmdline.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c > index 08da2b1..cde0a00 100644 > --- a/app/test-pmd/cmdline.c > +++ b/app/test-pmd/cmdline.c > @@ -9631,6 +9631,9 @@ dump_socket_mem(FILE *f) > socket_stats.alloc_count, > socket_stats.free_count); > } > + > + if (total == 0) > + return; > fprintf(f, > "Total : size(M) total: %.6lf alloc: %.6lf(%.3lf%%) free: %.6lf \tcount alloc: %-4u free: %u\n", > (double)total / (1024 * 1024), (double)alloc / (1024 * 1024), > Hi Connor, Not sure if the value can be zero on practice, but if the issue is found via static analyzer tool, instead of return from function without any output what about following instead: - (double)alloc * 100 / (double)total, + total ? ((double)alloc * 100 / (double)total) : 0,