From: Nick Alcock Date: Thu, 9 Aug 2012 23:33:14 +0000 (+0100) Subject: ctf: fix off-by-one in emitted array bounds X-Git-Tag: v4.1.12-92~313^2~127 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fa9f3942a92d05f2a7e9387c7a8b68c29aef8de9;p=users%2Fjedix%2Flinux-maple.git ctf: fix off-by-one in emitted array bounds We were treating arrays described by DW_AT_count and DW_AT_upper_bound identically, but in a language like C with zero-based arrays they are not: DW_AT_upper_bound does not give the number of members unless you add one to it. Signed-off-by: Nick Alcock --- diff --git a/scripts/dwarf2ctf/dwarf2ctf.c b/scripts/dwarf2ctf/dwarf2ctf.c index 2464b02496d5..87ffd6a275e3 100644 --- a/scripts/dwarf2ctf/dwarf2ctf.c +++ b/scripts/dwarf2ctf/dwarf2ctf.c @@ -3200,6 +3200,14 @@ static Dwarf_Word private_subrange_dimensions(Dwarf_Die *die) return 0; dwarf_formudata(&nelem_attr, &nelems); + + /* + * Upper bounds indicate that we have one more element than that, since + * C starts counting at zero. + */ + if (dwarf_hasattr(die, DW_AT_upper_bound)) + nelems++; + return nelems; }