[Pdbg] [PATCH 5/5] libpdbg: Return immediate parent if class is NULL

Amitay Isaacs amitay at ozlabs.org
Thu Aug 16 15:57:56 AEST 2018


This avoids the segfault if class is NULL.  Also, this api can be used
to traverse the tree by explicitly setting class=NULL.

Signed-off-by: Amitay Isaacs <amitay at ozlabs.org>
---
 libpdbg/libpdbg.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/libpdbg/libpdbg.c b/libpdbg/libpdbg.c
index 522bec9..810e045 100644
--- a/libpdbg/libpdbg.c
+++ b/libpdbg/libpdbg.c
@@ -89,6 +89,9 @@ struct pdbg_target *pdbg_target_parent(const char *class, struct pdbg_target *ta
 {
 	struct pdbg_target *parent;
 
+	if (!class)
+		return target->parent;
+
 	for (parent = target->parent; parent && parent->parent; parent = parent->parent) {
 		if (!strcmp(class, pdbg_target_class_name(parent)))
 			return parent;
-- 
2.17.1



More information about the Pdbg mailing list