Report of the static analyzer:
An integer overflow may occur in the calculation of `gray_level` due to
the multiplication of `(unsigned)i * 100`. This can happen when `i` is
close to the maximum value of `unsigned int` (4294967295), causing the
intermediate result to exceed the range of `unsigned int`.

Corrections explained:
1. Use `uint64_t` for intermediate calculations to avoid overflow.
2. Ensure `height` is not zero to prevent division by zero.

The logic of the progress bar remains unchanged, but the code is now
more robust and safe against edge cases.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <[email protected]>

---
 miscutils/fbsplash.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c
index 2934d8eb7..96644865e 100644
--- a/miscutils/fbsplash.c
+++ b/miscutils/fbsplash.c
@@ -353,7 +353,7 @@ static void fb_drawprogressbar(unsigned percent)
                while (i >= 0) {
                        // draw one-line thick "rectangle"
                        // top line will have gray lvl 200, bottom one 100
-                       unsigned gray_level = 100 + (unsigned)i*100 / height;
+                       unsigned gray_level = 100 + (unsigned)i / height * 100; 
                        fb_drawfullrectangle(
                                        left_x, y, pos_x, y,
                                        gray_level, gray_level, gray_level);
-- 
2.30.2

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to