BUILD: cli: clear a maybe-unused warning on some older compilers
authorWilly Tarreau <w@1wt.eu>
Sat, 20 Nov 2021 18:17:38 +0000 (19:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 10 Jan 2022 07:36:40 +0000 (08:36 +0100)
The SHOW_TOT() and SHOW_AVG() macros used in cli_io_handler_show_activity()
produce a warning on gcc 4.7 on MIPS with threads disabled because the
compiler doesn't know that global.nbthread is necessarily non-null, hence
that at least one iteration is performed. Let's just change the loop for
a do {} while () that lets the compiler know it's always initialized. It
also has the tiny benefit of making the code shorter.

(cherry picked from commit 97b5d07a3e5a33552327bac2e4c9c6a0496f7b5e)
Signed-off-by: Willy Tarreau <w@1wt.eu>
(cherry picked from commit b9aac36d8d8d3bb05c785aa8f6630338d078f64a)
Signed-off-by: Willy Tarreau <w@1wt.eu>

src/cli.c

index a89d313..454a85e 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1219,8 +1219,10 @@ static int cli_io_handler_show_activity(struct appctx *appctx)
                unsigned int _v[MAX_THREADS];                           \
                unsigned int _tot;                                      \
                const unsigned int _nbt = global.nbthread;              \
-               for (_tot = t = 0; t < _nbt; t++)                       \
+               _tot = t = 0;                                           \
+               do {                                                    \
                        _tot += _v[t] = (x);                            \
+               } while (++t < _nbt);                                   \
                if (_nbt == 1) {                                        \
                        chunk_appendf(&trash, " %u\n", _tot);           \
                        break;                                          \
@@ -1237,8 +1239,10 @@ static int cli_io_handler_show_activity(struct appctx *appctx)
                unsigned int _v[MAX_THREADS];                           \
                unsigned int _tot;                                      \
                const unsigned int _nbt = global.nbthread;              \
-               for (_tot = t = 0; t < _nbt; t++)                       \
+               _tot = t = 0;                                           \
+               do {                                                    \
                        _tot += _v[t] = (x);                            \
+               } while (++t < _nbt);                                   \
                if (_nbt == 1) {                                        \
                        chunk_appendf(&trash, " %u\n", _tot);           \
                        break;                                          \