[Pdbg] [PATCH 4/6] libpdbg: Fix clang warning -Wuninitialized

Alistair Popple alistair at popple.id.au
Tue Jul 2 11:57:34 AEST 2019


On Wednesday, 19 June 2019 1:15:48 PM AEST Amitay Isaacs wrote:
> Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
> ---
>  libpdbg/device.c | 4 ++--
>  libpdbg/target.c | 2 +-
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libpdbg/device.c b/libpdbg/device.c
> index b7fd49f..b71170c 100644
> --- a/libpdbg/device.c
> +++ b/libpdbg/device.c
> @@ -162,7 +162,7 @@ static int dt_cmp_subnodes(const struct pdbg_target *a,
> const struct pdbg_target
> 
>  static bool dt_attach_root(struct pdbg_target *parent, struct pdbg_target
> *root) {
> -	struct pdbg_target *node;
> +	struct pdbg_target *node = NULL;

This looks like it might be an actual bug though as if the list_add_before() 
call dereferences node which might be NULL (or uninitialised without this 
patch).

>  	assert(!root->parent);
> 
> @@ -305,7 +305,7 @@ static struct pdbg_target *dt_find_by_path(struct
> pdbg_target *root, const char static struct dt_property
> *dt_find_property(const struct pdbg_target *node, const char *name)
>  {
> -	struct dt_property *i;
> +	struct dt_property *i = NULL;
> 
>  	list_for_each(&node->properties, i, list)

Do we know why clang thinks the list_for_each() child can be used 
uninitialised?

>  		if (strcmp(i->name, name) == 0)
> diff --git a/libpdbg/target.c b/libpdbg/target.c
> index 40fe690..066f616 100644
> --- a/libpdbg/target.c
> +++ b/libpdbg/target.c
> @@ -283,7 +283,7 @@ struct pdbg_target *require_target_parent(struct
> pdbg_target *target) /* Finds the given class. Returns NULL if not found.
> */
>  struct pdbg_target_class *find_target_class(const char *name)
>  {
> -	struct pdbg_target_class *target_class;
> +	struct pdbg_target_class *target_class = NULL;
> 
>  	list_for_each(&target_classes, target_class, class_head_link)
>  		if (!strcmp(target_class->name, name))




More information about the Pdbg mailing list