From: Rusty Russell Date: Mon, 19 Nov 2012 00:23:09 +0000 (+1030) Subject: tal: tal_parent(NULL) should be NULL. X-Git-Url: https://git.ozlabs.org/?p=ccan;a=commitdiff_plain;h=dfe59969500a0c4e3b82ce6e7f8227d1a6e7b178;ds=sidebyside tal: tal_parent(NULL) should be NULL. Signed-off-by: Rusty Russell --- diff --git a/ccan/tal/tal.c b/ccan/tal/tal.c index 9fed477f..ff25db19 100644 --- a/ccan/tal/tal.c +++ b/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; diff --git a/ccan/tal/tal.h b/ccan/tal/tal.h index da71ca3f..da448d8f 100644 --- a/ccan/tal/tal.h +++ b/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); diff --git a/ccan/tal/test/run.c b/ccan/tal/test/run.c index 69ffa2d3..3d3799c5 100644 --- a/ccan/tal/test/run.c +++ b/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);