ACK: [PATCH 09/10] lib: fwts_framework: avoid division by zero in % calculations

IvanHu ivan.hu at canonical.com
Tue May 6 03:20:40 UTC 2014


On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> Coverity Scan is warning about potential division by zero, so guard
> against that, even it if it impossible unless fwts is configured with
> no tests.
>
> Signed-off-by: Colin Ian King <colin.king at canonical.com>
> ---
>   src/lib/src/fwts_framework.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_framework.c b/src/lib/src/fwts_framework.c
> index 669a944..7d8646c 100644
> --- a/src/lib/src/fwts_framework.c
> +++ b/src/lib/src/fwts_framework.c
> @@ -365,11 +365,12 @@ void fwts_framework_minor_test_progress(fwts_framework *fw, const int percent, c
>   	if (width > 256)
>   		width = 256;
>
> -	if (percent >=0 && percent <=100)
> +	if (percent >= 0 && percent <= 100)
>   		fw->minor_test_progress = percent;
>
> -	major_percent = (float)100.0 / (float)fw->major_tests_total;
> -	minor_percent = ((float)major_percent / (float)fw->current_major_test->ops->total_tests);
> +	major_percent = fw->major_tests_total ? (float)100.0 / (float)fw->major_tests_total : 100.0;
> +	minor_percent = fw->current_major_test->ops->total_tests ?
> +			((float)major_percent / (float)fw->current_major_test->ops->total_tests) : 0.0;
>   	process_percent = ((float)minor_percent / 100.0);
>
>   	progress = (float)(fw->current_major_test_num-1) * major_percent;
>

Acked-by: Ivan Hu <ivan.hu at canonical.com>



More information about the fwts-devel mailing list