[PATCH 1/2] xcursor: Fix allocation based on string length

Kristian Høgsberg hoegsberg at gmail.com
Tue Oct 9 20:01:13 PDT 2012


On Tue, Oct 09, 2012 at 06:46:21PM +0100, Rob Bradford wrote:
> From: Rob Bradford <rob at linux.intel.com>
> 
> strlen() doesn't include the terminating NUL. Therefore when allocating a
> block of memory to hold something equivalent to the length of the string we
> must increment to take the NUL byte into consideration.

Yeah, that's a little tricky, but it looks right to me.

Kristian

> Signed-off-by: Rob Bradford <rob at linux.intel.com>
> ---
>  cursor/xcursor.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cursor/xcursor.c b/cursor/xcursor.c
> index 1f66bce..7a9662a 100644
> --- a/cursor/xcursor.c
> +++ b/cursor/xcursor.c
> @@ -757,7 +757,7 @@ _XcursorThemeInherits (const char *full)
>  		if (*l != '=') continue;
>  		l++;
>  		while (*l == ' ') l++;
> -		result = malloc (strlen (l));
> +		result = malloc (strlen (l) + 1);
>  		if (result)
>  		{
>  		    r = result;
> -- 
> 1.7.11.2
> 
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel


More information about the wayland-devel mailing list