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 9C782A0C41; Wed, 12 May 2021 18:54:01 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7D67B4003F; Wed, 12 May 2021 18:54:01 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mails.dpdk.org (Postfix) with ESMTP id E3BDE4003E for ; Wed, 12 May 2021 18:53:59 +0200 (CEST) IronPort-SDR: kl97nIUqT3c53RjvY0fyrSCuMbmx7wudBxA2InxppyX7VY+TxVk51C0Z9NqX4Ea3DSt+NyTCW1 iyY7Lm7WOKHA== X-IronPort-AV: E=McAfee;i="6200,9189,9982"; a="220730161" X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="220730161" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2021 09:53:59 -0700 IronPort-SDR: F5sLw0rty65fh8gFGc7hzeji2t2N91hk1MKM7CAmNaY4fxW9wgDQiGIS5AEutdsbzYwtzcr7u8 WD47rqnuucWw== X-IronPort-AV: E=Sophos;i="5.82,293,1613462400"; d="scan'208";a="625477290" Received: from bricha3-mobl.ger.corp.intel.com ([10.252.19.33]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-SHA; 12 May 2021 09:53:57 -0700 Date: Wed, 12 May 2021 17:53:54 +0100 From: Bruce Richardson To: "Min Hu (Connor)" Cc: dev@dpdk.org, ferruh.yigit@intel.com, anatoly.burakov@intel.com, thomas@monjalon.net Message-ID: References: <1619163330-25960-1-git-send-email-humin29@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1619163330-25960-1-git-send-email-humin29@huawei.com> 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" 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? /Bruce