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 03EA1A0C45; Thu, 13 May 2021 03:10:42 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 77DE54067E; Thu, 13 May 2021 03:10:42 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 72DB14003F for ; Thu, 13 May 2021 03:10:41 +0200 (CEST) Received: from dggeme756-chm.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4FgYS95YltzYhLd; Thu, 13 May 2021 09:08:09 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggeme756-chm.china.huawei.com (10.3.19.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Thu, 13 May 2021 09:10:38 +0800 From: "Min Hu (Connor)" To: CC: , , Date: Thu, 13 May 2021 09:10:37 +0800 Message-ID: <1620868237-32724-1-git-send-email-humin29@huawei.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1619163330-25960-1-git-send-email-humin29@huawei.com> References: <1619163330-25960-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggeme756-chm.china.huawei.com (10.3.19.102) X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH v2] test: fix division by zero 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" 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) --- 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