[PATCH v2 libXi] Set ndevices to 0 in the error case

Peter Hutterer peter.hutterer at who-t.net
Tue Oct 11 09:24:12 UTC 2016


On Sat, Oct 08, 2016 at 11:35:57AM +0200, Niels Ole Salscheider wrote:
> v2: Fix formating issues

tbh, I usually prefer not to touch any parameters on errors. This should
better be fixed in the man page to specify the exact behaviour.

Cheers,
   Peter

> Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>
> ---
>  src/XListDev.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/src/XListDev.c b/src/XListDev.c
> index d0c6bf2..f47ad97 100644
> --- a/src/XListDev.c
> +++ b/src/XListDev.c
> @@ -189,8 +189,10 @@ XListInputDevices(
>      XExtDisplayInfo *info = XInput_find_display(dpy);
>  
>      LockDisplay(dpy);
> -    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
> +    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) {
> +	*ndevices = 0;
>  	return ((XDeviceInfo *) NULL);
> +    }
>  
>      GetReq(ListInputDevices, req);
>      req->reqType = info->codes->major_opcode;
> @@ -199,6 +201,7 @@ XListInputDevices(
>      if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
>  	UnlockDisplay(dpy);
>  	SyncHandle();
> +	*ndevices = 0;
>  	return (XDeviceInfo *) NULL;
>      }
>  
> @@ -212,6 +215,7 @@ XListInputDevices(
>  	    _XEatDataWords(dpy, rep.length);
>  	    UnlockDisplay(dpy);
>  	    SyncHandle();
> +	    *ndevices = 0;
>  	    return (XDeviceInfo *) NULL;
>  	}
>  	_XRead(dpy, (char *)list, rlen);
> @@ -220,15 +224,19 @@ XListInputDevices(
>  	sav_any = any;
>  	end = (char *)list + rlen;
>  	for (i = 0; i < *ndevices; i++, list++) {
> -            if(SizeClassInfo(&any, end - (char *)any, (int)list->num_classes, &s))
> -                goto out;
> +            if(SizeClassInfo(&any, end - (char *)any, (int)list->num_classes, &s)) {
> +		*ndevices = 0;
> +		goto out;
> +            }
>              size += s;
>  	}
>  
>  	Nptr = ((unsigned char *)list) + rlen;
>  	for (i = 0, nptr = (unsigned char *)any; i < *ndevices; i++) {
> -	    if (nptr >= Nptr)
> +	    if (nptr >= Nptr) {
> +		*ndevices = 0;
>  		goto out;
> +            }
>  	    size += *nptr + 1;
>  	    nptr += (*nptr + 1);
>  	}
> @@ -238,6 +246,7 @@ XListInputDevices(
>  	    XFree((char *)slist);
>  	    UnlockDisplay(dpy);
>  	    SyncHandle();
> +	    *ndevices = 0;
>  	    return (XDeviceInfo *) NULL;
>  	}
>  	sclist = clist;
> -- 
> 2.10.1


More information about the xorg-devel mailing list