diff options
author | Egbert Eich <eich@suse.com> | 2014-02-11 12:54:04 +0100 |
---|---|---|
committer | Egbert Eich <eich@suse.com> | 2014-02-19 14:08:58 +0100 |
commit | 591474f9fac0e06c48abed4edfda22edb3e36cf9 (patch) | |
tree | 63c1edc9b35438279317046c5471418eb2047843 | |
parent | 7e56966e917d9389965910c9d28f4047d51d4349 (diff) |
Avoid 'division by zero' in xf86ScaleAxis()
If minPressure == wcmMaxZ then the range left to scale is 0. Catch
this condition and act appropriately.
Signed-off-by: Egbert Eich <eich@suse.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jason Gerecke <killertofu@gmail.com>
-rw-r--r-- | src/wcmCommon.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/wcmCommon.c b/src/wcmCommon.c index 97f7765..209565c 100644 --- a/src/wcmCommon.c +++ b/src/wcmCommon.c @@ -1071,12 +1071,17 @@ normalizePressure(const WacomDevicePtr priv, const WacomDeviceState *ds) WacomCommonPtr common = priv->common; double pressure; int p = ds->pressure; + int range_left; /* normalize pressure to 0..FILTER_PRESSURE_RES */ - pressure = xf86ScaleAxis(p - priv->minPressure, - FILTER_PRESSURE_RES, 0, - common->wcmMaxZ - priv->minPressure, - 0); + range_left = common->wcmMaxZ - priv->minPressure; + if (range_left >= 1) + pressure = xf86ScaleAxis(p - priv->minPressure, + FILTER_PRESSURE_RES, 0, + range_left, + 0); + else + pressure = FILTER_PRESSURE_RES; return (int)pressure; } |