From 6ebba52da22cd2c6b6a5cd6c565ff8addde725a7 Mon Sep 17 00:00:00 2001 From: Kyle Manna Date: Mon, 17 Aug 2015 18:53:16 -0700 Subject: [PATCH] capn: Avoid uninitialized values * Return null when appropriate and assign a value earlier. --- capn.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/capn.c b/capn.c index 40690f9..9ae5633 100644 --- a/capn.c +++ b/capn.c @@ -187,7 +187,7 @@ end: static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) { struct capn_tree **x; - struct capn_segment *y; + struct capn_segment *y = NULL; if (s && s->id == id) return s; @@ -196,7 +196,6 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment * if (id < c->segnum) { x = &c->segtree; - y = NULL; while (*x) { y = (struct capn_segment*) *x; if (id == y->id) { @@ -207,6 +206,9 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment * x = &y->hdr.link[1]; } } + } else { + /* Otherwise `x` may be uninitialized */ + return NULL; } s = c->lookup ? c->lookup(c->user, id) : NULL;