reading_composer: fix slider reading description 35/244335/1
authorKamil Konieczny <k.konieczny@samsung.com>
Thu, 17 Sep 2020 09:55:45 +0000 (11:55 +0200)
committerKamil Konieczny <k.konieczny@samsung.com>
Thu, 17 Sep 2020 09:55:45 +0000 (11:55 +0200)
When slider values are not initialized or are set to zero,
this can result in division by 0.0 that can give unpredictable
values. Add some checks before division.

Change-Id: Ib269c962519191fcc3699076542ca021228cd1ef

src/reading_composer.c

index 1806056fb6643d9c476c339f529279ff73bf88f8..076bb1965f6ac80c84f972673795cd6b869a7a66 100644 (file)
@@ -46,7 +46,16 @@ TIZEN_PROD_STATIC void add_slider_description(Eina_Strbuf *buf, AtspiAccessibleR
        int max_val = (int)((rm->upper + add_for_rounding) * mul_for_rounding);
        int min_val = (int)((rm->lower + add_for_rounding) * mul_for_rounding);
 
-       int percent = ((val - min_val) / (double)(abs(max_val - min_val))) * 100;
+       int percent;
+       if (min_val >= max_val)
+               percent = 0;
+       else if (val <= min_val)
+               percent = 0;
+       else if (val >= max_val)
+               percent = 100;
+       else
+               percent = ((val - min_val) / (double)(abs(max_val - min_val))) * 100;
+
        char buf_percent[64] = "\0";
 
        g_snprintf(buf_percent, sizeof(buf_percent), "%d", percent);