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

Amitay Isaacs amitay at ozlabs.org
Tue Jul 2 13:46:50 AEST 2019


On Tue, 2019-07-02 at 11:57 +1000, Alistair Popple wrote:
> 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?

  CC       libpdbg/la-device.lo
../../libpdbg/device.c:310:35: error: variable 'i' is uninitialized
when used here [-Werror,-Wuninitialized]
        list_for_each(&node->properties, i, list)
                                         ^
../../ccan/list/list.h:386:40: note: expanded from macro
'list_for_each'
        list_for_each_off(h, i, list_off_var_(i, member))
                                              ^
../../ccan/list/list.h:523:21: note: expanded from macro
'list_off_var_'
        (container_off_var(var, member) +               \
                           ^~~
../../ccan/container_of/container_of.h:106:13: note: expanded from
macro 'container_off_var'
        ((char *)&(var)->member - (char *)(var))
                   ^~~
../../ccan/list/list.h:457:54: note: expanded from macro
'list_for_each_off'
  for (i = list_node_to_off_(list_debug(h)->n.next,
(off));             \
                                                     ^~~
../../libpdbg/device.c:308:23: note: initialize the variable 'i' to
silence this warning
        struct dt_property *i;
                             ^
                              = NULL
1 error generated.

> 
> >  		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))
> 
> 

Amitay.
-- 

Windows NT 4.0 does no longer support i386 processors ?
Get a Pentium Pro, no one will notice the difference !



More information about the Pdbg mailing list