]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
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>
Sat, 20 Nov 2021 19:15:37 +0000 (20:15 +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.

src/cli.c

index ec5283f27f5f7bc93a9cd4f2ff374f47cac77964..3b068031fb30b0423fff3e9cb283e3fac77c472a 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1368,8 +1368,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;                                          \
@@ -1386,8 +1388,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;                                          \