Skip to content

Commit abfd6f3

Browse files
committed
BUILD: trace: silence a bogus build warning at -Og
gcc-13.3 at -Og emits an incorrect build warning in trace.c about a possibly initialized variable: In file included from include/haproxy/api.h:35, from src/trace.c:22: src/trace.c: In function 'trace_parse_cmd': include/haproxy/bug.h:431:17: warning: 'arg' may be used uninitialized [-Wmaybe-uninitialized] 431 | free(*__x); \ | ^~~~~~~~~~ src/trace.c:1136:9: note: in expansion of macro 'ha_free' 1136 | ha_free(&oarg); | ^~~~~~~ src/trace.c:1008:15: note: 'arg' was declared here 1008 | char *arg, *oarg; | ^~~ The warning is obviously wrong since the field is initialized in one of the two branches of an "if" whose complementary one returns. But the compiler doesn't seem to see this because the if is in fact two ifs each with an opposite condition: "if (arg_src)" then "if (!arg_src)". Let's just move upwards the default one that returns and eliminate the other one. Reading the diff with "git diff -b" better shows the tiny change. It could be backported to 3.0.
1 parent ef73fe2 commit abfd6f3

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

src/trace.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,33 +1008,6 @@ int trace_parse_cmd(const char *arg_src, char **errmsg)
10081008
char *arg, *oarg;
10091009
char *saveptr;
10101010

1011-
if (arg_src) {
1012-
if (strcmp(arg_src, "help") == 0) {
1013-
memprintf(errmsg,
1014-
"-dt activates traces on stderr output via the command-line.\n"
1015-
"Without argument, all registered trace sources are activated with error level as filter.\n"
1016-
"A list can be specified as argument to configure several trace sources with comma as separator.\n"
1017-
"Each entry can contains the trace name, a log level and a verbosity using colon as separator.\n"
1018-
"Every fields are optional and can be left empty, or with a colon to specify the next one.\n\n"
1019-
"An empty name or the alias 'all' will activate all registered sources.\n"
1020-
"Verbosity cannot be configured in this case except 'quiet' as their values are specific to each source.\n\n"
1021-
"Examples:\n"
1022-
"-dt activate every sources on error level\n"
1023-
"-dt all:user activate every sources on user level\n"
1024-
"-dt h1 activate HTTP/1 traces on error level\n"
1025-
"-dt h2:data activate HTTP/2 traces on data level\n"
1026-
"-dt quic::clean,qmux::minimal\n activate both QUIC transport and MUX traces on error level with their custom verbosity\n");
1027-
return -1;
1028-
}
1029-
1030-
/* keep a copy of the ptr for strtok */
1031-
oarg = arg = strdup(arg_src);
1032-
if (!arg) {
1033-
memprintf(errmsg, "Can't allocate !");
1034-
return -2;
1035-
}
1036-
}
1037-
10381011
if (!arg_src) {
10391012
/* No trace specification, activate all sources on error level. */
10401013
struct trace_source *src = NULL;
@@ -1044,6 +1017,31 @@ int trace_parse_cmd(const char *arg_src, char **errmsg)
10441017
return 0;
10451018
}
10461019

1020+
if (strcmp(arg_src, "help") == 0) {
1021+
memprintf(errmsg,
1022+
"-dt activates traces on stderr output via the command-line.\n"
1023+
"Without argument, all registered trace sources are activated with error level as filter.\n"
1024+
"A list can be specified as argument to configure several trace sources with comma as separator.\n"
1025+
"Each entry can contains the trace name, a log level and a verbosity using colon as separator.\n"
1026+
"Every fields are optional and can be left empty, or with a colon to specify the next one.\n\n"
1027+
"An empty name or the alias 'all' will activate all registered sources.\n"
1028+
"Verbosity cannot be configured in this case except 'quiet' as their values are specific to each source.\n\n"
1029+
"Examples:\n"
1030+
"-dt activate every sources on error level\n"
1031+
"-dt all:user activate every sources on user level\n"
1032+
"-dt h1 activate HTTP/1 traces on error level\n"
1033+
"-dt h2:data activate HTTP/2 traces on data level\n"
1034+
"-dt quic::clean,qmux::minimal\n activate both QUIC transport and MUX traces on error level with their custom verbosity\n");
1035+
return -1;
1036+
}
1037+
1038+
/* keep a copy of the ptr for strtok */
1039+
oarg = arg = strdup(arg_src);
1040+
if (!arg) {
1041+
memprintf(errmsg, "Can't allocate trace source!");
1042+
return -2;
1043+
}
1044+
10471045
while ((str = strtok_r(arg, ",", &saveptr))) {
10481046
struct trace_source *src = NULL;
10491047
char *field, *name;

0 commit comments

Comments
 (0)