[PATCH] revolve possible null pointer dereference issue found by cppcheck

Michal Srb msrb at suse.com
Mon Apr 9 07:43:04 UTC 2018


On pondělí 9. dubna 2018 9:31:54 CEST Ilya Shipitsin wrote:
> [dix/inpututils.c:909] -> [dix/inpututils.c:905]: (warning) Either the
> condition 'if(list)' is redundant or there is possible null pointer
> dereference: list.

I think this is a false positive by cppcheck. It looks like it misinterprets 
the `list.next` in the macro as dereferencing the `list` variable.

The `nt_list_init(opt, list.next)` macro expands to:

  (opt)->list.next = NULL

So wrapping it in the `if (list)` condition is not correct.

Michal Srb

> ---
>  dix/inpututils.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/dix/inpututils.c b/dix/inpututils.c
> index 6bff9efab..f4c386a24 100644
> --- a/dix/inpututils.c
> +++ b/dix/inpututils.c
> @@ -902,7 +902,9 @@ input_option_new(InputOption *list, const char *key,
> const char *value) if (!opt)
>          return NULL;
> 
> -    nt_list_init(opt, list.next);
> +    if (list)
> +        nt_list_init(opt, list.next);
> +
>      input_option_set_key(opt, key);
>      input_option_set_value(opt, value);




More information about the xorg-devel mailing list