]> git.ozlabs.org Git - ccan/commitdiff
tal: tal_parent(NULL) should be NULL.
authorRusty Russell <rusty@rustcorp.com.au>
Mon, 19 Nov 2012 00:23:09 +0000 (10:53 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Mon, 19 Nov 2012 00:23:09 +0000 (10:53 +1030)
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ccan/tal/tal.c
ccan/tal/tal.h
ccan/tal/test/run.c

index 9fed477fe9595bd4e85d5243f1315c602915a830..ff25db19afb8a3b16da50ef254687a85b50cc71e 100644 (file)
@@ -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;
index da71ca3f2f9f3f2b38dae2fb07c866b8833c8bad..da448d8f22ad8813520299546a51ce09c0a00705 100644 (file)
@@ -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);
 
index 69ffa2d3dc3248de0cf7ceeeaa43963c0aa9c8e4..3d3799c55492b989a59720d98423b7ccfbee1f9e 100644 (file)
@@ -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);