From: Min Hu (Connor) Date: Thu, 13 May 2021 01:10:37 +0000 (+0800) Subject: test: fix division by zero X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=07b3c7d8e3b6513044d8f5cc45359cc42c14eb18;p=dpdk.git test: fix division by zero 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) Acked-by: Bruce Richardson --- diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c index a7be8aa71a..4f625873e5 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; }