Skip to content

Commit 53c89b0

Browse files
chenxy1988Kernel Patches Daemon
authored and
Kernel Patches Daemon
committed
libbpf: fix warnings "'pad_type' 'pad_bits' 'new_off' may be used uninitialized"
When turn on the yocto DEBUG_BUILD flag, the build options for gcc would enable maybe-uninitialized, and following warnings would be reported as below: | btf_dump.c: In function 'btf_dump_emit_bit_padding': | btf_dump.c:916:4: error: 'pad_type' may be used uninitialized in this function [-Werror=maybe-uninitialized] | 916 | btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type, | | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 917 | in_bitfield ? new_off - cur_off : 0); | | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | btf_dump.c:929:6: error: 'pad_bits' may be used uninitialized in this function [-Werror=maybe-uninitialized] | 929 | if (bits == pad_bits) { | | ^ | btf_dump.c:913:28: error: 'new_off' may be used uninitialized in this function [-Werror=maybe-uninitialized] | 913 | (new_off == next_off && roundup(cur_off, next_align * 8) != new_off) || | | ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | HOSTLD scripts/mod/modpost Signed-off-by: Xiangyu Chen <[email protected]>
1 parent a9aa9e7 commit 53c89b0

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

tools/lib/bpf/btf_dump.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d,
867867
} pads[] = {
868868
{"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8}
869869
};
870-
int new_off, pad_bits, bits, i;
871-
const char *pad_type;
870+
int new_off = 0, pad_bits = 0, bits, i;
871+
const char *pad_type = NULL;
872872

873873
if (cur_off >= next_off)
874874
return; /* no gap */

0 commit comments

Comments
 (0)