[PATCH libinput] evdev-mt-touchpad: check calloc result

Peter Hutterer peter.hutterer at who-t.net
Tue Apr 22 17:53:31 PDT 2014


On Tue, Apr 15, 2014 at 11:15:35PM +0200, Carlos Olmedo Escobar wrote:
> Check the value returned by calloc.
> ---
>  src/evdev-mt-touchpad.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
> index bbbd8f3..9ec1682 100644
> --- a/src/evdev-mt-touchpad.c
> +++ b/src/evdev-mt-touchpad.c
> @@ -25,6 +25,7 @@
>  #include <assert.h>
>  #include <math.h>
>  #include <stdbool.h>
> +#include <stdio.h>
>  
>  #include "evdev-mt-touchpad.h"
>  
> @@ -721,6 +722,10 @@ tp_init_slots(struct tp_dispatch *tp,
>  	}
>  	tp->touches = calloc(tp->ntouches,
>  			     sizeof(struct tp_touch));
> +	if (!tp->touches) {
> +	        fprintf(stderr, "Failed to initialize slots.");
> +	        return -1;
> +	}

Please use log_error() or the associated macros for this, though in this
case a simple return -1 is sufficient (we don't have a lot of logging yet
anyway)

Cheers,
   Peter

>  
>  	return 0;
>  }
> -- 
> 1.9.2
 


More information about the wayland-devel mailing list