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 BC5F9A0C45; Thu, 13 May 2021 03:11:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id AAB564067E; Thu, 13 May 2021 03:11:28 +0200 (CEST) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 0379E4003F for ; Thu, 13 May 2021 03:11:26 +0200 (CEST) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.58]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4FgYSs0Y8vzsRJj; Thu, 13 May 2021 09:08:45 +0800 (CST) Received: from [10.67.103.128] (10.67.103.128) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.498.0; Thu, 13 May 2021 09:11:23 +0800 To: Bruce Richardson CC: , , , References: <1619163330-25960-1-git-send-email-humin29@huawei.com> From: "Min Hu (Connor)" Message-ID: Date: Thu, 13 May 2021 09:11:23 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.103.128] X-CFilter-Loop: Reflected Subject: Re: [dpdk-dev] [PATCH] 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" ÔÚ 2021/5/13 0:53, Bruce Richardson дµÀ: > On Fri, Apr 23, 2021 at 03:35:30PM +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) >> --- >> app/test/test_reciprocal_division_perf.c | 5 +++-- >> 1 file changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/app/test/test_reciprocal_division_perf.c b/app/test/test_reciprocal_division_perf.c >> index a7be8aa..2647308 100644 >> --- a/app/test/test_reciprocal_division_perf.c >> +++ b/app/test/test_reciprocal_division_perf.c >> @@ -143,7 +143,7 @@ test_reciprocal_division_perf(void) >> "result %"PRIu64"", >> nresult_u64, rresult_u64); >> result = 1; >> - break; >> + goto err; >> } >> } >> >> @@ -182,7 +182,7 @@ test_reciprocal_division_perf(void) >> dividend_u64, divisor_u64, >> nresult_u64, rresult_u64); >> result = 1; >> - break; >> + goto err; >> } >> } >> printf("64bit Division results:\n"); >> @@ -195,6 +195,7 @@ test_reciprocal_division_perf(void) >> printf("Cycles per division(reciprocal) : %3.2f\n", >> ((double)tot_cyc_r)/i); >> >> +err: >> return result; >> } >> > This looks correct as far as it goes, but I believe the same fix is needed > at lines 66 and 106 too. > > One other thing I note is that currently the test will move on to the > next test case on failure, due to break, but using the goto will change > that behaviour. Therefore, I wonder if a better fix is to skip the > printouts if i == 0 in each case? > Good point, fixed in v2, thanks Bruce. > /Bruce > . >