bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] libbpf: fix false uninitialized variable warning
@ 2019-09-25 18:30 Andrii Nakryiko
  2019-09-25 20:27 ` Daniel Borkmann
  0 siblings, 1 reply; 2+ messages in thread
From: Andrii Nakryiko @ 2019-09-25 18:30 UTC (permalink / raw)
  To: bpf, netdev, ast, daniel; +Cc: andrii.nakryiko, kernel-team, Andrii Nakryiko

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
compiler.

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))
 					decls->cnt--;
 				else
 					break;
 			}
 
 			if (decls->cnt == 0) {
 				btf_dump_emit_name(d, fname, last_was_ptr);
 				btf_dump_printf(d, "[%u]", a->nelems);
 				return;
 			}
 
+			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);
 			return;
 		}
 		case BTF_KIND_FUNC_PROTO: {
 			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
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-09-25 20:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-25 18:30 [PATCH bpf] libbpf: fix false uninitialized variable warning Andrii Nakryiko
2019-09-25 20:27 ` Daniel Borkmann

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).