[PATCH xf86-input-synaptics 2/2] Ensure history delta computations are signed

Peter Hutterer peter.hutterer at who-t.net
Wed Feb 8 06:54:51 PST 2012


On Tue, Feb 07, 2012 at 01:07:08PM -0800, Chase Douglas wrote:
> Signed-off-by: Chase Douglas <chase.douglas at canonical.com>
> ---
>  src/synaptics.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/src/synaptics.c b/src/synaptics.c
> index a4c1e5a..106b5ee 100644
> --- a/src/synaptics.c
> +++ b/src/synaptics.c
> @@ -1791,7 +1791,7 @@ HandleTapProcessing(SynapticsPrivate *priv, struct SynapticsHwState *hw,
>  }
>  
>  #define HIST(a) (priv->move_hist[((priv->hist_index - (a) + SYNAPTICS_MOVE_HISTORY) % SYNAPTICS_MOVE_HISTORY)])
> -#define HIST_DELTA(a, b, e) ((HIST((a)).e) - (HIST((b)).e))
> +#define HIST_DELTA(a, b, e) ((int)((HIST((a)).e) - (HIST((b)).e)))

this only casts the result to a signed int, the actual computation is still
undefined for b > a. With the revert, HIST_DELTA is only used in one place
so we could either do it there or just write a helper function like this

diff --git a/src/synaptics.c b/src/synaptics.c
index a4c1e5a..fbc5515 100644
--- a/src/synaptics.c
+++ b/src/synaptics.c
@@ -1791,7 +1791,18 @@ HandleTapProcessing(SynapticsPrivate *priv, struct SynapticsHwState *hw,
 }
 
 #define HIST(a) (priv->move_hist[((priv->hist_index - (a) + SYNAPTICS_MOVE_HISTORY) % SYNAPTICS_MOVE_HISTORY)])
-#define HIST_DELTA(a, b, e) ((HIST((a)).e) - (HIST((b)).e))
+
+static inline unsigned int
+hist_time_delta(SynapticsMoveHistRec a, SynapticsMoveHistRec b)
+{
+    if (a.millis < b.millis)
+    {
+        xf86Msg(X_ERROR, "Bug: history a < b");
+        return 0;
+    }
+
+    return a.millis - b.millis;
+}
 
 static void
 store_history(SynapticsPrivate *priv, int x, int y, CARD32 millis)
@@ -2016,7 +2027,7 @@ start_coasting(SynapticsPrivate *priv, struct SynapticsHwState *hw,
     priv->scroll.coast_delta_x = 0.0;
 
     if ((priv->scroll.packets_this_scroll > 3) && (para->coasting_speed > 0.0)) {
-	double pkt_time = HIST_DELTA(0, 3, millis) / 1000.0;
+	double pkt_time = hist_time_delta(HIST(0), HIST(3)) / 1000.0;
 	if (vert && !circ) {
 	    double dy = estimate_delta(HIST(0).y, HIST(1).y, HIST(2).y, HIST(3).y);
 	    int sdelta = para->scroll_dist_vert;

Cheers,
  Peter

>  static void
>  store_history(SynapticsPrivate *priv, int x, int y, CARD32 millis)
> -- 
> 1.7.8.3
> 


More information about the xorg-devel mailing list