capn: Avoid uninitialized values
* Return null when appropriate and assign a value earlier.
This commit is contained in:
parent
376b63fb81
commit
6ebba52da2
1 changed files with 4 additions and 2 deletions
6
capn.c
6
capn.c
|
|
@ -187,7 +187,7 @@ end:
|
||||||
|
|
||||||
static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) {
|
static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *s, uint32_t id) {
|
||||||
struct capn_tree **x;
|
struct capn_tree **x;
|
||||||
struct capn_segment *y;
|
struct capn_segment *y = NULL;
|
||||||
|
|
||||||
if (s && s->id == id)
|
if (s && s->id == id)
|
||||||
return s;
|
return s;
|
||||||
|
|
@ -196,7 +196,6 @@ static struct capn_segment *lookup_segment(struct capn* c, struct capn_segment *
|
||||||
|
|
||||||
if (id < c->segnum) {
|
if (id < c->segnum) {
|
||||||
x = &c->segtree;
|
x = &c->segtree;
|
||||||
y = NULL;
|
|
||||||
while (*x) {
|
while (*x) {
|
||||||
y = (struct capn_segment*) *x;
|
y = (struct capn_segment*) *x;
|
||||||
if (id == y->id) {
|
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];
|
x = &y->hdr.link[1];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
/* Otherwise `x` may be uninitialized */
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = c->lookup ? c->lookup(c->user, id) : NULL;
|
s = c->lookup ? c->lookup(c->user, id) : NULL;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue