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;