Browse Source

tal: tal_parent(NULL) should be NULL.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Rusty Russell 13 years ago
parent
commit
dfe5996950
3 changed files with 10 additions and 3 deletions
  1. 6 1
      ccan/tal/tal.c
  2. 1 1
      ccan/tal/tal.h
  3. 3 1
      ccan/tal/test/run.c

+ 6 - 1
ccan/tal/tal.c

@@ -638,7 +638,12 @@ tal_t *tal_next(const tal_t *root, const tal_t *prev)
 tal_t *tal_parent(const tal_t *ctx)
 {
         struct group *group;
-        struct tal_hdr *t = debug_tal(to_tal_hdr(ctx));
+        struct tal_hdr *t;
+
+	if (!ctx)
+		return NULL;
+
+	t = debug_tal(to_tal_hdr(ctx));
 
 	while (!(group = find_property(t, GROUP)))
 		t = t->next;

+ 1 - 1
ccan/tal/tal.h

@@ -159,7 +159,7 @@ tal_t *tal_next(const tal_t *root, const tal_t *prev);
  * tal_parent - get the parent of a tal object.
  * @ctx: The tal allocated object.
  *
- * Returns the parent, which may be NULL.
+ * Returns the parent, which may be NULL.  Returns NULL if @ctx is NULL.
  */
 tal_t *tal_parent(const tal_t *ctx);
 

+ 3 - 1
ccan/tal/test/run.c

@@ -7,10 +7,12 @@ int main(void)
 	char *parent, *c[4], *p;
 	int i, j;
 
-	plan_tests(10);
+	plan_tests(12);
 
 	parent = tal(NULL, char);
 	ok1(parent);
+	ok1(tal_parent(parent) == NULL);
+	ok1(tal_parent(NULL) == NULL);
 
 	for (i = 0; i < 4; i++)
 		c[i] = tal(parent, char);