bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrii Nakryiko <andriin@fb.com>
To: <bpf@vger.kernel.org>, <netdev@vger.kernel.org>, <ast@fb.com>,
Cc: <andrii.nakryiko@gmail.com>, <kernel-team@fb.com>,
	Andrii Nakryiko <andriin@fb.com>
Subject: [PATCH bpf] libbpf: fix false uninitialized variable warning
Date: Wed, 25 Sep 2019 11:30:38 -0700	[thread overview]
Message-ID: <20190925183038.2755521-1-andriin@fb.com> (raw)

Some compilers emit warning for potential uninitialized next_id usage.
The code is correct, but control flow is too complicated for some
compilers to figure this out. Re-initialize next_id to satisfy

Signed-off-by: Andrii Nakryiko <andriin@fb.com>
 tools/lib/bpf/btf_dump.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 715967762312..84b0661db7f3 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -1140,60 +1140,61 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
 		case BTF_KIND_ARRAY: {
 			const struct btf_array *a = btf_array(t);
 			const struct btf_type *next_t;
 			__u32 next_id;
 			bool multidim;
 			 * GCC has a bug
 			 * (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=8354)
 			 * which causes it to emit extra const/volatile
 			 * modifiers for an array, if array's element type has
 			 * const/volatile modifiers. Clang doesn't do that.
 			 * In general, it doesn't seem very meaningful to have
 			 * a const/volatile modifier for array, so we are
 			 * going to silently skip them here.
 			while (decls->cnt) {
 				next_id = decls->ids[decls->cnt - 1];
 				next_t = btf__type_by_id(d->btf, next_id);
 				if (btf_is_mod(next_t))
 			if (decls->cnt == 0) {
 				btf_dump_emit_name(d, fname, last_was_ptr);
 				btf_dump_printf(d, "[%u]", a->nelems);
+			next_id = decls->ids[decls->cnt - 1];
 			next_t = btf__type_by_id(d->btf, next_id);
 			multidim = btf_is_array(next_t);
 			/* we need space if we have named non-pointer */
 			if (fname[0] && !last_was_ptr)
 				btf_dump_printf(d, " ");
 			/* no parentheses for multi-dimensional array */
 			if (!multidim)
 				btf_dump_printf(d, "(");
 			btf_dump_emit_type_chain(d, decls, fname, lvl);
 			if (!multidim)
 				btf_dump_printf(d, ")");
 			btf_dump_printf(d, "[%u]", a->nelems);
 			const struct btf_param *p = btf_params(t);
 			__u16 vlen = btf_vlen(t);
 			int i;
 			btf_dump_emit_mods(d, decls);
 			if (decls->cnt) {
 				btf_dump_printf(d, " (");
 				btf_dump_emit_type_chain(d, decls, fname, lvl);
 				btf_dump_printf(d, ")");
 			} else {
 				btf_dump_emit_name(d, fname, last_was_ptr);
 			btf_dump_printf(d, "(");
 			 * Clang for BPF target generates func_proto with no

             reply	other threads:[~2019-09-25 18:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-25 18:30 Andrii Nakryiko [this message]
2019-09-25 20:27 ` [PATCH bpf] libbpf: fix false uninitialized variable warning Daniel Borkmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190925183038.2755521-1-andriin@fb.com \
    --to=andriin@fb.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=ast@fb.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=netdev@vger.kernel.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).