[PATCH libXi] XListInputDevices: Do not modify ndevices in case of an error

Peter Hutterer peter.hutterer at who-t.net
Mon Oct 17 03:21:03 UTC 2016


On Sat, Oct 15, 2016 at 02:06:42PM +0200, Niels Ole Salscheider wrote:
> Output parameters must only be modified if there is no error.
> 
> Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>

see this patch here please
https://patchwork.freedesktop.org/patch/115414/

Cheers,
   Peter

> ---
>  src/XListDev.c | 17 +++++++++--------
>  1 file changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/src/XListDev.c b/src/XListDev.c
> index b2bad72..f4e37ba 100644
> --- a/src/XListDev.c
> +++ b/src/XListDev.c
> @@ -202,8 +202,8 @@ XListInputDevices(
>  	return (XDeviceInfo *) NULL;
>      }
>  
> -    if ((*ndevices = rep.ndevices)) {	/* at least 1 input device */
> -	size = *ndevices * sizeof(XDeviceInfo);
> +    if (rep.ndevices) {			/* at least 1 input device */
> +	size = rep.ndevices * sizeof(XDeviceInfo);
>  	if (rep.length < (INT_MAX >> 2)) {
>  	    rlen = rep.length << 2;	/* multiply length by 4    */
>  	    slist = list = Xmalloc(rlen);
> @@ -216,17 +216,17 @@ XListInputDevices(
>  	}
>  	_XRead(dpy, (char *)list, rlen);
>  
> -	any = (xAnyClassPtr) ((char *)list + (*ndevices * sizeof(xDeviceInfo)));
> +	any = (xAnyClassPtr) ((char *)list + (rep.ndevices * sizeof(xDeviceInfo)));
>  	sav_any = any;
>  	end = (char *)list + rlen;
> -	for (i = 0; i < *ndevices; i++, list++) {
> +	for (i = 0; i < rep.ndevices; i++, list++) {
>              if(SizeClassInfo(&any, end - (char *)any, (int)list->num_classes, &s))
>                  goto out;
>              size += s;
>  	}
>  
>  	Nptr = ((unsigned char *)list) + rlen;
> -	for (i = 0, nptr = (unsigned char *)any; i < *ndevices; i++) {
> +	for (i = 0, nptr = (unsigned char *)any; i < rep.ndevices; i++) {
>  	    if (nptr >= Nptr)
>  		goto out;
>  	    size += *nptr + 1;
> @@ -242,10 +242,10 @@ XListInputDevices(
>  	}
>  	sclist = clist;
>  	Any = (XAnyClassPtr) ((char *)clist +
> -			      (*ndevices * sizeof(XDeviceInfo)));
> +			      (rep.ndevices * sizeof(XDeviceInfo)));
>  	list = slist;
>  	any = sav_any;
> -	for (i = 0; i < *ndevices; i++, list++, clist++) {
> +	for (i = 0; i < rep.ndevices; i++, list++, clist++) {
>  	    clist->type = list->type;
>  	    clist->id = list->id;
>  	    clist->use = list->use;
> @@ -258,7 +258,7 @@ XListInputDevices(
>  	clist = sclist;
>  	nptr = (unsigned char *)any;
>  	Nptr = (unsigned char *)Any;
> -	for (i = 0; i < *ndevices; i++, clist++) {
> +	for (i = 0; i < rep.ndevices; i++, clist++) {
>  	    clist->name = (char *)Nptr;
>  	    memcpy(Nptr, nptr + 1, *nptr);
>  	    Nptr += (*nptr);
> @@ -266,6 +266,7 @@ XListInputDevices(
>  	    nptr += (*nptr + 1);
>  	}
>      }
> +    *ndevices = rep.ndevices;
>  
>    out:
>      XFree((char *)slist);
> -- 
> 2.10.1
> 


More information about the xorg-devel mailing list