Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
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;
* 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);
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);