tablet: Fix divide by zero error. 'count' could be zero submit/tizen/20220208.100129 submit/tizen/20220209.072019
authorDuna Oh <duna.oh@samsung.com>
Tue, 8 Feb 2022 06:39:18 +0000 (15:39 +0900)
committerDuna Oh <duna.oh@samsung.com>
Tue, 8 Feb 2022 07:05:51 +0000 (16:05 +0900)
src/evdev-tablet.c

index e0980e91963face33abf46633dd66d6e9252429f..3e567e91d5383aa962620096f7301d72e2b2f659 100644 (file)
@@ -676,6 +676,9 @@ tablet_smoothen_axes(const struct tablet_dispatch *tablet,
        size_t count = tablet_history_size(tablet);
        struct tablet_axes smooth = { 0 };
 
+       if (count <= 0)
+               return;
+
        for (i = 0; i < count; i++) {
                const struct tablet_axes *a = tablet_history_get(tablet, i);
 
@@ -686,11 +689,11 @@ tablet_smoothen_axes(const struct tablet_dispatch *tablet,
                smooth.tilt.y += a->tilt.y;
        }
 
-       axes->point.x = smooth.point.x/count;
-       axes->point.y = smooth.point.y/count;
+       axes->point.x = smooth.point.x/(double)count;
+       axes->point.y = smooth.point.y/(double)count;
 
-       axes->tilt.x = smooth.tilt.x/count;
-       axes->tilt.y = smooth.tilt.y/count;
+       axes->tilt.x = smooth.tilt.x/(double)count;
+       axes->tilt.y = smooth.tilt.y/(double)count;
 }
 
 static bool