summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlistair Popple <alistair@popple.id.au>2017-12-11 14:46:16 +1100
committerAlistair Popple <alistair@popple.id.au>2017-12-11 15:22:04 +1100
commit5b65a68d47e452b875b4aa59a4924a719129136a (patch)
tree85132e04d15b60d9417c4b25f0489f73e87785cc
parentabf61b33793a8e01fbc07e4f30f7c50e40906a4f (diff)
downloadpdbg-5b65a68d47e452b875b4aa59a4924a719129136a.tar.gz
pdbg-5b65a68d47e452b875b4aa59a4924a719129136a.zip
libpdbg: Fix pdbg_target_index
The pdbg_target_index is supposed to walk up the tree looking for an index. Instead it caused segfaults when the current target has no index assigned. Fix the code up to make it do what it's supposed to. Signed-off-by: Alistair Popple <alistair@popple.id.au>
-rw-r--r--libpdbg/libpdbg.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index a971125..6194048 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -102,11 +102,14 @@ void pdbg_disable_target(struct pdbg_target *target)
/* Searches up the tree and returns the first valid index found */
uint32_t pdbg_target_index(struct pdbg_target *target)
{
- uint32_t index;
- struct dt_node *dn = target->dn;
+ struct dt_node *dn;
+
+ for (dn = target->dn; dn && dn->target->index == -1; dn = dn->parent);
- for (index = dn->target->index; index == -1; dn = dn->parent);
- return index;
+ if (!dn)
+ return -1;
+ else
+ return dn->target->index;
}
/* Searched up the tree for the first target of the right class and returns its index */
OpenPOWER on IntegriCloud