DPDK patches and discussions
 help / color / mirror / Atom feed
From: Ferruh Yigit <ferruh.yigit@intel.com>
To: "Min Hu (Connor)" <humin29@huawei.com>, dev@dpdk.org
Cc: xiaoyun.li@intel.com
Subject: Re: [dpdk-dev] [PATCH] app/testpmd: fix division by zero bug
Date: Mon, 26 Apr 2021 12:20:13 +0100	[thread overview]
Message-ID: <cf3d7fe7-c905-6417-11ac-38f65ea5c7a0@intel.com> (raw)
In-Reply-To: <1619005102-38437-1-git-send-email-humin29@huawei.com>

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) <humin29@huawei.com>
> ---
>   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,

  reply	other threads:[~2021-04-26 11:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-21 11:38 Min Hu (Connor)
2021-04-26 11:20 ` Ferruh Yigit [this message]
2021-04-26 11:57 ` [dpdk-dev] [PATCH v2] " Min Hu (Connor)
2021-04-29 13:36   ` Ferruh Yigit
2021-04-26 11:58 ` [dpdk-dev] [PATCH] " Min Hu (Connor)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cf3d7fe7-c905-6417-11ac-38f65ea5c7a0@intel.com \
    --to=ferruh.yigit@intel.com \
    --cc=dev@dpdk.org \
    --cc=humin29@huawei.com \
    --cc=xiaoyun.li@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).