From: "Min Hu (Connor)" <humin29@huawei.com>
To: <dev@dpdk.org>
Cc: <ferruh.yigit@intel.com>, <bruce.richardson@intel.com>,
<thomas@monjalon.net>
Subject: [dpdk-dev] [PATCH v2] test: fix division by zero
Date: Thu, 13 May 2021 09:10:37 +0800 [thread overview]
Message-ID: <1620868237-32724-1-git-send-email-humin29@huawei.com> (raw)
In-Reply-To: <1619163330-25960-1-git-send-email-humin29@huawei.com>
Variable i is used as a denominator which may be zero, and
this may result in segmentation fault.
This patch fixed it.
Fixes: 948bc3d6d095 ("test: add reciprocal based division")
Cc: stable@dpdk.org
Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
v2:
* to skip the printouts if i == 0.
---
app/test/test_reciprocal_division_perf.c | 41 +++++++++++++++++++-------------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c
index a7be8aa..4f62587 100644
--- a/app/test/test_reciprocal_division_perf.c
+++ b/app/test/test_reciprocal_division_perf.c
@@ -71,10 +71,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -111,11 +113,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
-
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -152,10 +155,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n\n",
+ ((double)tot_cyc_r)/i);
+ }
tot_cyc_n = 0;
tot_cyc_r = 0;
@@ -190,10 +195,12 @@ test_reciprocal_division_perf(void)
tot_cyc_n);
printf("Total number of cycles reciprocal division : %"PRIu64"\n",
tot_cyc_r);
- printf("Cycles per division(normal) : %3.2f\n",
- ((double)tot_cyc_n)/i);
- printf("Cycles per division(reciprocal) : %3.2f\n",
- ((double)tot_cyc_r)/i);
+ if (i != 0) {
+ printf("Cycles per division(normal) : %3.2f\n",
+ ((double)tot_cyc_n)/i);
+ printf("Cycles per division(reciprocal) : %3.2f\n",
+ ((double)tot_cyc_r)/i);
+ }
return result;
}
--
2.7.4
next prev parent reply other threads:[~2021-05-13 1:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 7:35 [dpdk-dev] [PATCH] " Min Hu (Connor)
2021-05-12 16:53 ` Bruce Richardson
2021-05-13 1:11 ` Min Hu (Connor)
2021-05-13 1:10 ` Min Hu (Connor) [this message]
2021-05-13 8:23 ` [dpdk-dev] [PATCH v2] " Bruce Richardson
2021-05-19 7:20 ` Thomas Monjalon
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=1620868237-32724-1-git-send-email-humin29@huawei.com \
--to=humin29@huawei.com \
--cc=bruce.richardson@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@intel.com \
--cc=thomas@monjalon.net \
/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).