From git@z Thu Jan 1 00:00:00 1970 Subject: [PATCH] tools lib subcmd: Fixed uninitialized use of variable in parse-options From: Michael Weiß Date: Wed, 31 Jul 2024 10:52:17 +0200 Message-Id: <20240731085217.94928-1-michael.weiss@aisec.fraunhofer.de> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Since commit ea558c86248b ("tools lib subcmd: Show parent options in help"), our debug images fail to build. For our Yocto-based GyroidOS, we build debug images with debugging enabled for all binaries including the kernel. Yocto passes the corresponding gcc option "-Og" also to the kernel HOSTCFLAGS. This results in the following build error: parse-options.c: In function ‘options__order’: parse-options.c:834:9: error: ‘o’ may be used uninitialized [-Werror=maybe-uninitialized] 834 | memcpy(&ordered[nr_opts], o, sizeof(*o)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ parse-options.c:812:30: note: ‘o’ was declared here 812 | const struct option *o, *p = opts; | ^ .. Fix it by initializing 'o' instead of 'p' in the above failing line 812. 'p' is initialized afterwards in the following for-loop anyway. I think that was the intention of the commit ea558c86248b ("tools lib subcmd: Show parent options in help") in the first place. Fixes: ea558c86248b ("tools lib subcmd: Show parent options in help") Signed-off-by: Michael Weiß --- tools/lib/subcmd/parse-options.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/lib/subcmd/parse-options.c b/tools/lib/subcmd/parse-options.c index 4b60ec03b0bb..2a3b51a690c7 100644 --- a/tools/lib/subcmd/parse-options.c +++ b/tools/lib/subcmd/parse-options.c @@ -809,7 +809,7 @@ static int option__cmp(const void *va, const void *vb) static struct option *options__order(const struct option *opts) { int nr_opts = 0, nr_group = 0, nr_parent = 0, len; - const struct option *o, *p = opts; + const struct option *o = opts, *p; struct option *opt, *ordered = NULL, *group; /* flatten the options that have parents */ -- 2.39.2