[PATCH 4/4] dix: Resize touch event history if the array is filled up

Peter Hutterer peter.hutterer at who-t.net
Thu Mar 16 23:10:09 UTC 2017


On Thu, Mar 16, 2017 at 12:29:44PM +0200, Timo Aaltonen wrote:
> From: Maarten Lankhorst <maarten.lankhorst at ubuntu.com>
> 
> Signed-off-by: Maarten Lankhorst <maarten.lankhorst at ubuntu.com>
> ---
>  dix/touch.c | 18 ++++++++++++++++--
>  1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/dix/touch.c b/dix/touch.c
> index 37902bd..efc7ef9 100644
> --- a/dix/touch.c
> +++ b/dix/touch.c
> @@ -430,11 +430,25 @@ TouchEventHistoryPush(TouchPointInfoPtr ti, const DeviceEvent *ev)
>      if (ev->flags & (TOUCH_CLIENT_ID | TOUCH_REPLAYING))
>          return;
>  
> +    if (ti->history_elements == ti->history_size - 1) {
> +        DeviceEvent *hist = NULL;
> +        size_t sz = ti->history_size * 2;
> +
> +        if (sz < 10000) {
> +            hist = realloc(ti->history, sz * sizeof(*hist));
> +
> +            if (hist) {
> +                ti->history = hist;
> +                ti->history_size = sz;
> +                memset(&hist[sz/2], 0, sizeof(*hist)*sz/2);

swap these around and memset first based on ti->history_elements and a
proper size-elements calculation. This avoids possible errors if history
size is ever an odd number (never going to happen, but...)

but do we even need the memset? if we're not copying the events correctly
and rely on zero memory then we'll have other problems.

Cheers,
   Peter


> +            }
> +        }
> +    }
> +
>      ti->history[ti->history_elements++] = *ev;
> -    /* FIXME: proper overflow fixes */
>      if (ti->history_elements > ti->history_size - 1) {
>          ti->history_elements = ti->history_size - 1;
> -        DebugF("source device %d: history size %zu overflowing for touch %u\n",
> +        ErrorF("source device %d: history size %zu overflowing for touch %u\n",
>                 ti->sourceid, ti->history_size, ti->client_id);
>      }
>  }
> -- 
> 2.7.4
> 
> _______________________________________________
> xorg-devel at lists.x.org: X.Org development
> Archives: http://lists.x.org/archives/xorg-devel
> Info: https://lists.x.org/mailman/listinfo/xorg-devel
> 


More information about the xorg-devel mailing list