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.
This commit is contained in:
Willy Tarreau 2020-11-06 13:19:18 +01:00
parent f5fe70620c
commit 4299528390

View File

@ -5129,7 +5129,8 @@ static int ssl_sock_handshake(struct connection *conn, unsigned int flag)
{ {
struct ssl_sock_ctx *ctx = conn->xprt_ctx; struct ssl_sock_ctx *ctx = conn->xprt_ctx;
int ret; int ret;
struct ssl_counters *counters, *counters_px; struct ssl_counters *counters = NULL;
struct ssl_counters *counters_px = NULL;
struct listener *li; struct listener *li;
struct server *srv; struct server *srv;
@ -5405,10 +5406,12 @@ reneg_ok:
global.ssl_fe_keys_max = global.ssl_fe_keys_per_sec.curr_ctr; global.ssl_fe_keys_max = global.ssl_fe_keys_per_sec.curr_ctr;
} }
++counters->sess; if (counters) {
++counters_px->sess; ++counters->sess;
++counters_px->sess;
}
} }
else { else if (counters) {
++counters->reused_sess; ++counters->reused_sess;
++counters_px->reused_sess; ++counters_px->reused_sess;
} }