[PATCH libXi] SizeClassInfo can return 0 even without an error

Peter Hutterer peter.hutterer at who-t.net
Thu Oct 13 01:12:33 UTC 2016


On Fri, Oct 07, 2016 at 09:46:44PM +0200, Niels Ole Salscheider wrote:
> Catch the error case separately. This fixes a few crashes on my computer.

others have mentioned this already, but "fixes a few crashes" is too generic
for a commit message. you should always explain *why* you're doing something
in as much detail as required for someone to reproduce or at least
understand the issue. in a few months time, most of us will have forgotten
what this patch was about and then rely on the commit message to refresh our
memory.

> Signed-off-by: Niels Ole Salscheider <niels_ole at salscheider-online.de>
> ---
>  src/XListDev.c | 21 ++++++++++-----------
>  1 file changed, 10 insertions(+), 11 deletions(-)
> 
> diff --git a/src/XListDev.c b/src/XListDev.c
> index f850cd0..d0c6bf2 100644
> --- a/src/XListDev.c
> +++ b/src/XListDev.c
> @@ -73,27 +73,27 @@ static int pad_to_xid(int base_size)
>      return ((base_size + padsize - 1)/padsize) * padsize;
>  }
>  
> -static size_t
> -SizeClassInfo(xAnyClassPtr *any, size_t len, int num_classes)
> +static int
> +SizeClassInfo(xAnyClassPtr *any, size_t len, int num_classes, size_t *size)
>  {
> -    int size = 0;
>      int j;
> +    *size = 0;

happy to merge this with this bit removed and adjusted so that size only
changes in the success case. but I will need a commit message that explains
bits in more detail.

Cheers,
   Peter

>      for (j = 0; j < num_classes; j++) {
>          switch ((*any)->class) {
>              case KeyClass:
> -                size += pad_to_xid(sizeof(XKeyInfo));
> +                *size += pad_to_xid(sizeof(XKeyInfo));
>                  break;
>              case ButtonClass:
> -                size += pad_to_xid(sizeof(XButtonInfo));
> +                *size += pad_to_xid(sizeof(XButtonInfo));
>                  break;
>              case ValuatorClass:
>                  {
>                      xValuatorInfoPtr v;
>  
>                      if (len < sizeof(v))
> -                        return 0;
> +                        return 1;
>                      v = (xValuatorInfoPtr) *any;
> -                    size += pad_to_xid(sizeof(XValuatorInfo) +
> +                    *size += pad_to_xid(sizeof(XValuatorInfo) +
>                          (v->num_axes * sizeof(XAxisInfo)));
>                      break;
>                  }
> @@ -101,11 +101,11 @@ SizeClassInfo(xAnyClassPtr *any, size_t len, int num_classes)
>                  break;
>          }
>          if ((*any)->length > len)
> -            return 0;
> +            return 1;
>          *any = (xAnyClassPtr) ((char *)(*any) + (*any)->length);
>      }
>  
> -    return size;
> +    return 0;
>  }
>  
>  static void
> @@ -220,8 +220,7 @@ XListInputDevices(
>  	sav_any = any;
>  	end = (char *)list + rlen;
>  	for (i = 0; i < *ndevices; i++, list++) {
> -            s = SizeClassInfo(&any, end - (char *)any, (int)list->num_classes);
> -            if (!s)
> +            if(SizeClassInfo(&any, end - (char *)any, (int)list->num_classes, &s))
>                  goto out;
>              size += s;
>  	}
> -- 
> 2.10.1
> 
> _______________________________________________
> 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