Instead of duplicating the check, move into a single function to avoid the usual bugs of one occurance getting updated but the others don't, etc.
Reported-by: Chris Bagwell <[email protected]> Signed-off-by: Peter Hutterer <[email protected]> --- src/wcmFilter.c | 17 ++++++++++++++--- src/wcmValidateDevice.c | 3 +-- src/wcmXCommand.c | 4 ++-- src/xf86Wacom.h | 2 ++ 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/wcmFilter.c b/src/wcmFilter.c index 38021a6..91b2f10 100644 --- a/src/wcmFilter.c +++ b/src/wcmFilter.c @@ -38,18 +38,29 @@ static void filterLine(int* pCurve, int nMax, int x0, int y0, int x1, int y1); static void filterIntuosStylus(WacomCommonPtr common, WacomFilterStatePtr state, WacomDeviceStatePtr ds); void wcmTilt2R(WacomDeviceStatePtr ds); + /***************************************************************************** - * wcmSetPressureCurve -- apply user-defined curve to pressure values + * wcmCheckPressureCurveValues -- check pressure curve values for sanity. + * Return TRUE if values are sane or FALSE otherwise. ****************************************************************************/ +int wcmCheckPressureCurveValues(int x0, int y0, int x1, int y1) +{ + return !((x0 < 0) || (x0 > 100) || (y0 < 0) || (y0 > 100) || + (x1 < 0) || (x1 > 100) || (y1 < 0) || (y1 > 100)); +} + +/***************************************************************************** + * wcmSetPressureCurve -- apply user-defined curve to pressure values + ****************************************************************************/ void wcmSetPressureCurve(WacomDevicePtr pDev, int x0, int y0, int x1, int y1) { int i; /* sanity check values */ - if ((x0 < 0) || (x0 > 100) || (y0 < 0) || (y0 > 100) || - (x1 < 0) || (x1 > 100) || (y1 < 0) || (y1 > 100)) return; + if (!wcmCheckPressureCurveValues(x0, y0, x1, y1)) + return; /* if curve is not allocated, do it now. */ if (!pDev->pPressCurve) diff --git a/src/wcmValidateDevice.c b/src/wcmValidateDevice.c index a7dd02c..5d8933d 100644 --- a/src/wcmValidateDevice.c +++ b/src/wcmValidateDevice.c @@ -387,8 +387,7 @@ int wcmParseOptions(LocalDevicePtr local, unsigned long* keys) { int a,b,c,d; if ((sscanf(s,"%d,%d,%d,%d",&a,&b,&c,&d) != 4) || - (a < 0) || (a > 100) || (b < 0) || (b > 100) || - (c < 0) || (c > 100) || (d < 0) || (d > 100)) + !wcmCheckPressureCurveValues(a, b, c, d)) xf86Msg(X_CONFIG, "%s: PressCurve not valid\n", local->name); else diff --git a/src/wcmXCommand.c b/src/wcmXCommand.c index df3194b..331b64a 100644 --- a/src/wcmXCommand.c +++ b/src/wcmXCommand.c @@ -331,8 +331,8 @@ int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, pcurve = (INT32*)prop->data; - if ((pcurve[0] > 100) || (pcurve[1] > 100) || - (pcurve[2] > 100) || (pcurve[3] > 100)) + if (!wcmCheckPressureCurveValues(pcurve[0], pcurve[1], + pcurve[2], pcurve[3])) return BadValue; if (IsCursor(priv) || IsPad (priv) || IsTouch (priv)) diff --git a/src/xf86Wacom.h b/src/xf86Wacom.h index e17c4be..c4bc16f 100644 --- a/src/xf86Wacom.h +++ b/src/xf86Wacom.h @@ -178,6 +178,8 @@ extern void wcmRotateCoordinates(LocalDevicePtr local, int* x, int* y); extern void wcmVirtualTabletSize(LocalDevicePtr local); extern void wcmVirtualTabletPadding(LocalDevicePtr local); +extern int wcmCheckPressureCurveValues(int x0, int y0, int x1, int y1); + /* device properties */ #if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3 extern int wcmSetProperty(DeviceIntPtr dev, Atom property, XIPropertyValuePtr prop, BOOL checkonly); -- 1.6.6.1 ------------------------------------------------------------------------------ Download Intel® Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev _______________________________________________ Linuxwacom-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/linuxwacom-devel
