From 4299528390ce197a06c0ef1d59a4696fa9c19c30 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 6 Nov 2020 13:19:18 +0100 Subject: [PATCH] BUILD: ssl: silence build warning on uninitialised counters Since commit d0447a7c3 ("MINOR: ssl: add counters for ssl sessions"), gcc 9+ complains about this: CC src/ssl_sock.o src/ssl_sock.c: In function 'ssl_sock_io_cb': src/ssl_sock.c:5416:3: warning: 'counters_px' may be used uninitialized in this function [-Wmaybe-uninitialized] 5416 | ++counters_px->reused_sess; | ^~~~~~~~~~~~~~~~~~~~~~~~~~ src/ssl_sock.c:5133:23: note: 'counters_px' was declared here 5133 | struct ssl_counters *counters, *counters_px; | ^~~~~~~~~~~ Either a listener or a server are expected there, so ther counters are always initialized and the compiler cannot know this. Let's preset them and test before updating the counter, we're not in a hot path here. No backport is needed. --- src/ssl_sock.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ssl_sock.c b/src/ssl_sock.c index c8ea19f14..9072752f2 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -5129,7 +5129,8 @@ static int ssl_sock_handshake(struct connection *conn, unsigned int flag) { struct ssl_sock_ctx *ctx = conn->xprt_ctx; int ret; - struct ssl_counters *counters, *counters_px; + struct ssl_counters *counters = NULL; + struct ssl_counters *counters_px = NULL; struct listener *li; struct server *srv; @@ -5405,10 +5406,12 @@ reneg_ok: global.ssl_fe_keys_max = global.ssl_fe_keys_per_sec.curr_ctr; } - ++counters->sess; - ++counters_px->sess; + if (counters) { + ++counters->sess; + ++counters_px->sess; + } } - else { + else if (counters) { ++counters->reused_sess; ++counters_px->reused_sess; }