From fa9f3942a92d05f2a7e9387c7a8b68c29aef8de9 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Fri, 10 Aug 2012 00:33:14 +0100 Subject: [PATCH] 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 --- scripts/dwarf2ctf/dwarf2ctf.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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; } -- 2.50.1