From 9b3db8ddb5b589b78fc5979673e7fd33300408bc Mon Sep 17 00:00:00 2001 From: Duna Oh Date: Tue, 8 Feb 2022 15:39:18 +0900 Subject: [PATCH] tablet: Fix divide by zero error. 'count' could be zero --- src/evdev-tablet.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/evdev-tablet.c b/src/evdev-tablet.c index 7ff97f2d..df898fd9 100644 --- a/src/evdev-tablet.c +++ b/src/evdev-tablet.c @@ -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 -- 2.34.1