[v2] test: fix division by zero

Message ID 1620868237-32724-1-git-send-email-humin29@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: Thomas Monjalon
Headers
Series [v2] test: fix division by zero |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot success github build: passed
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS

Commit Message

humin (Q) May 13, 2021, 1:10 a.m. UTC
  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(-)
  

Comments

Bruce Richardson May 13, 2021, 8:23 a.m. UTC | #1
On Thu, May 13, 2021 at 09:10:37AM +0800, Min Hu (Connor) wrote:
> 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(-)
> 
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  
Thomas Monjalon May 19, 2021, 7:20 a.m. UTC | #2
13/05/2021 10:23, Bruce Richardson:
> On Thu, May 13, 2021 at 09:10:37AM +0800, Min Hu (Connor) wrote:
> > 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(-)
> > 
> Acked-by: Bruce Richardson <bruce.richardson@intel.com>

Applied, thanks.
  

Patch

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;
 }