diff mbox series

[bpf] libbpf: fix false uninitialized variable warning

Message ID 20190925183038.2755521-1-andriin@fb.com
State Accepted
Delegated to: BPF Maintainers
Headers show
Series [bpf] libbpf: fix false uninitialized variable warning | expand

Commit Message

Andrii Nakryiko Sept. 25, 2019, 6:30 p.m. UTC
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(+)

Comments

Daniel Borkmann Sept. 25, 2019, 8:27 p.m. UTC | #1
On Wed, Sep 25, 2019 at 11:30:38AM -0700, Andrii Nakryiko wrote:
> 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>

Applied, thanks!
diff mbox series

Patch

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