From a7394e1b72706abcd5bdda254dfd86877fee400b Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 27 Mar 2018 15:06:02 +0200 Subject: [PATCH] BUG/MINOR: hpack: fix harmless use of uninitialized value in hpack_dht_insert A warning is reported here by valgrind on first pass in hpack_dht_insert(). The cause is that the not-yet-initialized dht->head is checked in hpack_dht_get_tail(), though the result is not used, making it have no impact. At the very least it confuses valgrind, and maybe it makes it harder for gcc to optimize the code path. Let's move the variable initialization around to shut it up. Thanks to Olivier for reporting this one. This fix may be backported to 1.8 at least to make valgrind usage less painful. --- src/hpack-tbl.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hpack-tbl.c b/src/hpack-tbl.c index 92601f3f9..02e5a5cfe 100644 --- a/src/hpack-tbl.c +++ b/src/hpack-tbl.c @@ -261,15 +261,11 @@ int hpack_dht_insert(struct hpack_dht *dht, struct ist name, struct ist value) if (!hpack_dht_make_room(dht, name.len + value.len)) return 0; - used = dht->used; - prev = head = dht->head; - wrap = dht->wrap; - tail = hpack_dht_get_tail(dht); - /* Now there is enough room in the table, that's guaranteed by the * protocol, but not necessarily where we need it. */ + used = dht->used; if (!used) { /* easy, the table was empty */ dht->front = dht->head = 0; @@ -281,6 +277,10 @@ int hpack_dht_insert(struct hpack_dht *dht, struct ist name, struct ist value) } /* compute the new head, used and wrap position */ + prev = head = dht->head; + wrap = dht->wrap; + tail = hpack_dht_get_tail(dht); + used++; head++;