[v2] test: fix division by zero
Checks
Commit Message
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
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>
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.
@@ -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;
}