On Sat, Apr 15, 2023 at 11:21:54PM +0800, James Raphael Tiovalen wrote:
> This commit adds various null pointer checks to some files in the `lib`
> and the `ovsdb` directories to fix several Coverity defects. These
> changes are grouped together as they perform similar checks, returning
> early or skipping some action if a null pointer is encountered.
> 
> Signed-off-by: James Raphael Tiovalen <[email protected]>

...

> diff --git a/lib/shash.c b/lib/shash.c
> index 2b1d55901..9ac8877f1 100644
> --- a/lib/shash.c
> +++ b/lib/shash.c
> @@ -207,11 +207,15 @@ shash_delete(struct shash *sh, struct shash_node *node)
>  char *
>  shash_steal(struct shash *sh, struct shash_node *node)
>  {
> -    char *name = node->name;
> +    if (node) {
> +        char *name = node->name;
>  
> -    hmap_remove(&sh->map, &node->node);
> -    free(node);
> -    return name;
> +        hmap_remove(&sh->map, &node->node);
> +        free(node);
> +        return name;
> +    } else {
> +        return NULL;
> +    }

Hi James,

FWIIW, I would lean towards:

    char *name;

    if (!node) {
        return NULL;
    }

    name = node->name;
    ...
    return name;


>  }

...
_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to