diff mbox series

[04/10] app/regex: fix division by zero

Message ID 1618839289-33224-5-git-send-email-humin29@huawei.com (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers show
Series fixes for clean code | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Min Hu (Connor) April 19, 2021, 1:34 p.m. UTC
Variable nb_jobs, which may be zero, is used as a denominator.

This patch fixed it.

Fixes: f5cffb7eb7fb ("app/regex: read data file once at startup")
Cc: stable@dpdk.org

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
---
 app/test-regex/main.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Ori Kam April 19, 2021, 5:48 p.m. UTC | #1
Hi Min,

> -----Original Message-----
> From: Min Hu (Connor) <humin29@huawei.com>
> Sent: Monday, April 19, 2021 4:35 PM
> Subject: [PATCH 04/10] app/regex: fix division by zero
> 
> Variable nb_jobs, which may be zero, is used as a denominator.
> 
> This patch fixed it.
> 
> Fixes: f5cffb7eb7fb ("app/regex: read data file once at startup")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
> ---
>  app/test-regex/main.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/app/test-regex/main.c b/app/test-regex/main.c
> index 8e665df..b49fa88 100644
> --- a/app/test-regex/main.c
> +++ b/app/test-regex/main.c
> @@ -725,9 +725,11 @@ main(int argc, char **argv)
>  	if (data_len <= 0)
>  		rte_exit(EXIT_FAILURE, "Error, can't read file, or file is
> empty.\n");
> 
> -	job_len = data_len / nb_jobs;
> -	if (job_len == 0)
> -		rte_exit(EXIT_FAILURE, "Error, To many jobs, for the given
> input.\n");
> +	if (!nb_jobs) {
> +		job_len = data_len / nb_jobs;
> +		if (job_len == 0)
> +			rte_exit(EXIT_FAILURE, "Error, To many jobs, for the
> given input.\n");
> +	}
> 
>  	if (job_len > nb_max_payload)
>  		rte_exit(EXIT_FAILURE, "Error, not enough jobs to cover
> input.\n");
> --
> 2.7.4

Acked-by: Ori Kam <orika@nvidia.com>
Thanks,
Ori
diff mbox series

Patch

diff --git a/app/test-regex/main.c b/app/test-regex/main.c
index 8e665df..b49fa88 100644
--- a/app/test-regex/main.c
+++ b/app/test-regex/main.c
@@ -725,9 +725,11 @@  main(int argc, char **argv)
 	if (data_len <= 0)
 		rte_exit(EXIT_FAILURE, "Error, can't read file, or file is empty.\n");
 
-	job_len = data_len / nb_jobs;
-	if (job_len == 0)
-		rte_exit(EXIT_FAILURE, "Error, To many jobs, for the given input.\n");
+	if (!nb_jobs) {
+		job_len = data_len / nb_jobs;
+		if (job_len == 0)
+			rte_exit(EXIT_FAILURE, "Error, To many jobs, for the given input.\n");
+	}
 
 	if (job_len > nb_max_payload)
 		rte_exit(EXIT_FAILURE, "Error, not enough jobs to cover input.\n");