[PATCH twm 2/3] Add sanity checking to avoid a possible NULL dereference

walter harms wharms at bfs.de
Mon May 16 08:19:13 PDT 2011



Am 12.05.2011 07:43, schrieb Jeremy Huddleston:
> 
> menus.c:934:26: warning: Access to field 'fore' results in a dereference of a null pointer (loaded from variable 'cur')
>             cur->hi_back = cur->fore = f3.pixel;
>                            ~~~  ^
> 
> Found-by: clang static analyzer
> Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>
> ---
>  src/menus.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/src/menus.c b/src/menus.c
> index 34a3c8e..395426f 100644
> --- a/src/menus.c
> +++ b/src/menus.c
> @@ -920,7 +920,7 @@ MakeMenu(MenuRoot *mr)
>  	b3.flags = DoRed | DoGreen | DoBlue;
>  
>  	num -= 1;
> -	for (i = 0, cur = start->next; i < num; i++, cur = cur->next)
> +	for (i = 0, cur = start->next; i < num && cur; i++, cur = cur->next)
>  	{
>  	    f3.red += fred;
>  	    f3.green += fgreen;

you are mixing two for loops, it would improve readability if you could
entangle that.

re,
 wh


More information about the xorg-devel mailing list