tablet: Fix divide by zero error. 'count' could be zero
authorDuna Oh <duna.oh@samsung.com>
Tue, 8 Feb 2022 06:39:18 +0000 (15:39 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 4 Feb 2025 10:03:45 +0000 (19:03 +0900)
src/evdev-tablet.c

index 7ff97f2da2bf2ff9a6602bdb258c76f98e45ca10..df898fd9b52fc7d4fdd954b352ea59c91f99b0a4 100644 (file)
@@ -763,6 +763,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);
 
@@ -773,11 +776,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