From f4d5a235717a67bd7ff7443d39846004d3b7cbce Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Fri, 22 Apr 2022 06:52:11 +0800 Subject: [PATCH] libc/fixedmatch: Avoid "divide by zero" error Signed-off-by: Xiang Xiao --- libs/libc/fixedmath/lib_ubsqrt.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libs/libc/fixedmath/lib_ubsqrt.c b/libs/libc/fixedmath/lib_ubsqrt.c index ed9dfdf8f9..342da15283 100644 --- a/libs/libc/fixedmath/lib_ubsqrt.c +++ b/libs/libc/fixedmath/lib_ubsqrt.c @@ -55,7 +55,7 @@ ub16_t ub32sqrtub16(ub32_t a) xk = (uint64_t)1 << 63; } - do + while (xk) { uint64_t xk1 = (xk + n / xk) >> 1; @@ -66,7 +66,6 @@ ub16_t ub32sqrtub16(ub32_t a) xk = xk1; } - while (1); /* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^32)' => 'sqrt(a) * 2^16', thus * 'xk' holds square root of 'a' in ub16_t format. @@ -101,7 +100,7 @@ ub8_t ub16sqrtub8(ub16_t a) xk = (uint32_t)1 << 31; } - do + while (xk) { uint32_t xk1 = (xk + n / xk) >> 1; @@ -112,7 +111,6 @@ ub8_t ub16sqrtub8(ub16_t a) xk = xk1; } - while (1); /* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^16)' => 'sqrt(a) * 2^8', thus * 'xk' holds square root of 'a' in ub8_t format.